diff --git a/src/app-utils/option-util.c b/src/app-utils/option-util.c index 26daf8d8b2..1a1bf84287 100644 --- a/src/app-utils/option-util.c +++ b/src/app-utils/option-util.c @@ -1,6 +1,5 @@ /********************************************************************\ * option-util.c -- GNOME<->guile option interface * - * Copyright (C) 1998,1999 Linas Vepstas * * Copyright (C) 2000 Dave Peticolas * * * * This program is free software; you can redistribute it and/or * @@ -32,7 +31,9 @@ #include "glib-helpers.h" #include "guile-util.h" #include "gnc-engine-util.h" +#include "gnc-err-popup.h" #include "guile-mappings.h" +#include "messages.h" #include @@ -1731,7 +1732,7 @@ gnc_commit_option(GNCOption *option) name = gnc_option_name(option); section = gnc_option_section(option); - gnc_send_gui_error("There is a problem with option %s:%s.\n%s", + gnc_send_gui_error(_("There is a problem with option %s:%s.\n%s"), section ? section : "(null)", name ? name : "(null)", message ? message : "(null)"); diff --git a/src/app-utils/prefs.scm b/src/app-utils/prefs.scm index 6f0dac22d6..e044a7d289 100644 --- a/src/app-utils/prefs.scm +++ b/src/app-utils/prefs.scm @@ -181,6 +181,11 @@ "d" (N_ "Enables support for the European Union EURO currency") (gnc:is-euro-currency-code (gnc:locale-default-iso-currency-code)))) +(gnc:register-configuration-option + (gnc:make-dateformat-option + (N_ "International") (N_ "Fancy Date Format") + "e" (N_ "The default date format used for fancy printed dates") #f)) + ;;; Register options diff --git a/src/backend/file/gnc-book-xml-v2.c b/src/backend/file/gnc-book-xml-v2.c index d36406871b..478e829fc9 100644 --- a/src/backend/file/gnc-book-xml-v2.c +++ b/src/backend/file/gnc-book-xml-v2.c @@ -183,7 +183,7 @@ book_id_handler (xmlNodePtr node, gpointer book_pdata) GUID *guid; guid = dom_tree_to_guid(node); - qof_book_set_guid(book, *guid); + qof_book_set_guid(book, guid); g_free(guid); diff --git a/src/backend/file/gnc-freqspec-xml-v2.c b/src/backend/file/gnc-freqspec-xml-v2.c index a6d8a69d12..b2a4634198 100644 --- a/src/backend/file/gnc-freqspec-xml-v2.c +++ b/src/backend/file/gnc-freqspec-xml-v2.c @@ -156,7 +156,7 @@ gnc_freqSpec_dom_tree_create( FreqSpec *fs ) ret = xmlNewNode( NULL, "gnc:freqspec" ); xmlSetProp( ret, "version", freqspec_version_string ); - xmlAddChild( ret, guid_to_dom_tree( "fs:id", &fs->guid ) ); + xmlAddChild( ret, guid_to_dom_tree( "fs:id", &fs->entity.guid ) ); xmlSub = text_to_dom_tree( "fs:ui_type", uiFreqTypeStrs[ xaccFreqSpecGetUIType(fs) ].str ); @@ -507,7 +507,7 @@ fs_guid_handler( xmlNodePtr node, gpointer data) fsParseData *fspd = data; GUID *guid; guid = dom_tree_to_guid( node ); - fspd->fs->guid = *guid; + fspd->fs->entity.guid = *guid; return TRUE; } diff --git a/src/backend/file/gnc-schedxaction-xml-v2.c b/src/backend/file/gnc-schedxaction-xml-v2.c index f704bb30bf..1e9f17956f 100644 --- a/src/backend/file/gnc-schedxaction-xml-v2.c +++ b/src/backend/file/gnc-schedxaction-xml-v2.c @@ -264,7 +264,7 @@ sx_id_handler( xmlNodePtr node, gpointer sx_pdata ) GUID *tmp = dom_tree_to_guid( node ); g_return_val_if_fail( tmp, FALSE ); - xaccSchedXactionSetGUID(sx, *tmp); + xaccSchedXactionSetGUID(sx, tmp); g_free( tmp ); return TRUE; @@ -668,15 +668,13 @@ gnc_schedXaction_end_handler(gpointer data_for_children, xaccAccountGetName( acct ), id ); /* FIXME: free existing template account. - * HUH????? We only execute this if there isn't - * currently an existing template account, don't we? - * - */ + * HUH????? We only execute this if there isn't + * currently an existing template account, don't we? + * + */ sx->template_acct = acct; } - - xaccSchedXactionSetDirtyness(sx, FALSE); xmlFreeNode( tree ); return successful; diff --git a/src/backend/file/gnc-transaction-xml-v2.c b/src/backend/file/gnc-transaction-xml-v2.c index 7391b327ab..a3032d936f 100644 --- a/src/backend/file/gnc-transaction-xml-v2.c +++ b/src/backend/file/gnc-transaction-xml-v2.c @@ -312,7 +312,7 @@ spl_account_handler(xmlNodePtr node, gpointer data) account = xaccAccountLookup (id, pdata->book); if (!account && gnc_transaction_xml_v2_testing && - !guid_equal (id, xaccGUIDNULL ())) + !guid_equal (id, guid_null ())) { account = xaccMallocAccount (pdata->book); xaccAccountSetGUID (account, id); @@ -338,7 +338,7 @@ spl_lot_handler(xmlNodePtr node, gpointer data) lot = gnc_lot_lookup (id, pdata->book); if (!lot && gnc_transaction_xml_v2_testing && - !guid_equal (id, xaccGUIDNULL ())) + !guid_equal (id, guid_null ())) { lot = gnc_lot_new (pdata->book); gnc_lot_set_guid (lot, *id); diff --git a/src/backend/file/io-gncbin-r.c b/src/backend/file/io-gncbin-r.c index 9dbc02b1a8..abdc4125a2 100644 --- a/src/backend/file/io-gncbin-r.c +++ b/src/backend/file/io-gncbin-r.c @@ -556,7 +556,9 @@ qof_session_load_from_binfile(QofBook *book, const char * datafile) return; } + xaccDisableDataScrubbing(); gnc_load_financials_from_fd(book, fd); + xaccEnableDataScrubbing(); close(fd); } diff --git a/src/backend/file/io-gncbin.h b/src/backend/file/io-gncbin.h index 14b2614ba9..ca2219027d 100644 --- a/src/backend/file/io-gncbin.h +++ b/src/backend/file/io-gncbin.h @@ -36,7 +36,7 @@ * * NOTE: These routines should not be used directly for file IO. They * are not inherently safe against file-locking errors. For direct - * file IO, the gnc-book's higher level functions should be used. + * file IO, the QofBook's higher level functions should be used. * * qof_session_load_from_binfile() will load the financial data * represented by the book's file_path into the indicated book. diff --git a/src/backend/file/io-gncxml-v1.c b/src/backend/file/io-gncxml-v1.c index df2ff11d15..fd747d552f 100644 --- a/src/backend/file/io-gncxml-v1.c +++ b/src/backend/file/io-gncxml-v1.c @@ -370,6 +370,7 @@ qof_session_load_from_xml_file(QofBook *book, const char *filename) g_return_val_if_fail(book, FALSE); g_return_val_if_fail(filename, FALSE); + xaccDisableDataScrubbing(); top_level_pr = gncxml_setup_for_read (&global_parse_status); g_return_val_if_fail(top_level_pr, FALSE); @@ -380,6 +381,7 @@ qof_session_load_from_xml_file(QofBook *book, const char *filename) &parse_result); sixtp_destroy(top_level_pr); + xaccEnableDataScrubbing(); if(parse_ok) { @@ -1384,8 +1386,8 @@ account_restore_after_child_handler(gpointer data_for_children, if(strcmp(child_result->tag, "slots") == 0) { kvp_frame *f = (kvp_frame *) child_result->data; g_return_val_if_fail(f, FALSE); - if(a->kvp_data) kvp_frame_delete(a->kvp_data); - a->kvp_data = f; + if(a->inst.kvp_data) kvp_frame_delete(a->inst.kvp_data); + a->inst.kvp_data = f; child_result->should_cleanup = FALSE; } else if(strcmp(child_result->tag, "currency") == 0) { @@ -2819,8 +2821,7 @@ txn_restore_after_child_handler(gpointer data_for_children, if(strcmp(child_result->tag, "slots") == 0) { kvp_frame *f = (kvp_frame *) child_result->data; g_return_val_if_fail(f, FALSE); - if(trans->kvp_data) kvp_frame_delete(trans->kvp_data); - trans->kvp_data = f; + qof_instance_set_slots(QOF_INSTANCE(trans),f); child_result->should_cleanup = FALSE; } return(TRUE); diff --git a/src/backend/file/io-gncxml-v2.c b/src/backend/file/io-gncxml-v2.c index 6b4c554b86..aca05c0429 100644 --- a/src/backend/file/io-gncxml-v2.c +++ b/src/backend/file/io-gncxml-v2.c @@ -37,6 +37,7 @@ #include "SX-book.h" #include "SX-book-p.h" #include "Transaction.h" +#include "TransactionP.h" #include "TransLog.h" #include "qofbackend-p.h" #include "qofbook.h" @@ -420,22 +421,20 @@ gnc_counter_sixtp_parser_create(void) return sixtp_dom_parser_new(gnc_counter_end_handler, NULL, NULL); } -#if 0 static void print_counter_data(load_counter *data) { - PINFO("Transactions: Total: %d, Loaded: %d\n", + PINFO("Transactions: Total: %d, Loaded: %d", data->transactions_total, data->transactions_loaded); - PINFO("Accounts: Total: %d, Loaded: %d\n", + PINFO("Accounts: Total: %d, Loaded: %d", data->accounts_total, data->accounts_loaded); - PINFO("Books: Total: %d, Loaded: %d\n", + PINFO("Books: Total: %d, Loaded: %d", data->books_total, data->books_loaded); - PINFO("Commodities: Total: %d, Loaded: %d\n", + PINFO("Commodities: Total: %d, Loaded: %d", data->commodities_total, data->commodities_loaded); - PINFO("Scheduled Tansactions: Total: %d, Loaded: %d\n", + PINFO("Scheduled Tansactions: Total: %d, Loaded: %d", data->schedXactions_total, data->schedXactions_loaded); } -#endif static void file_rw_feedback (sixtp_gdv2 *gd, const char *type) @@ -700,14 +699,23 @@ qof_session_load_from_xml_file_v2(FileBackend *fbe, QofBook *book) /* stop logging while we load */ xaccLogDisable (); + xaccDisableDataScrubbing(); if(!gnc_xml_parse_file(top_parser, fbe->fullpath, generic_callback, gd, book)) { sixtp_destroy(top_parser); xaccLogEnable (); + xaccEnableDataScrubbing(); goto bail; } + DEBUGCMD (print_counter_data(&gd->counter)); + + /* destroy the parser */ + sixtp_destroy (top_parser); + g_free(gd); + + xaccEnableDataScrubbing(); /* Mark the book as saved */ qof_book_mark_saved (book); @@ -732,16 +740,9 @@ qof_session_load_from_xml_file_v2(FileBackend *fbe, QofBook *book) */ xaccAccountGroupCommitEdit (grp); - /* destroy the parser */ - sixtp_destroy (top_parser); - /* start logging again */ xaccLogEnable (); - g_free(gd); - /* DEBUG */ - /* print_counter_data(&gd->counter); */ - return TRUE; bail: diff --git a/src/backend/file/io-utils.c b/src/backend/file/io-utils.c index 48b98376a8..fdf4866eb3 100644 --- a/src/backend/file/io-utils.c +++ b/src/backend/file/io-utils.c @@ -29,10 +29,10 @@ #include #include "Group.h" -#include "gnc-book.h" #include "gnc-xml.h" #include "gnc-xml.h" #include "io-utils.h" +#include "qofbook.h" /* diff --git a/src/backend/file/io-utils.h b/src/backend/file/io-utils.h index 235cb165c3..a2b1c9f6cb 100644 --- a/src/backend/file/io-utils.h +++ b/src/backend/file/io-utils.h @@ -27,9 +27,9 @@ #include -#include "gnc-book.h" #include "Group.h" #include "io-gncxml-v2.h" +#include "qofbook.h" void write_account_group(FILE *out, AccountGroup *grp, sixtp_gdv2 *gd); void write_accounts(FILE *out, QofBook *book, sixtp_gdv2 *gd); diff --git a/src/backend/file/sixtp-dom-generators.c b/src/backend/file/sixtp-dom-generators.c index 7c614adc09..f5124b2a85 100644 --- a/src/backend/file/sixtp-dom-generators.c +++ b/src/backend/file/sixtp-dom-generators.c @@ -33,9 +33,9 @@ #include "sixtp-dom-generators.h" #include "sixtp-utils.h" -#include "GNCId.h" #include "gnc-engine-util.h" #include "kvp_frame.h" +#include "qofid.h" static short module = MOD_IO; diff --git a/src/backend/file/sixtp-dom-generators.h b/src/backend/file/sixtp-dom-generators.h index 27313a46f7..f4ceba9f9f 100644 --- a/src/backend/file/sixtp-dom-generators.h +++ b/src/backend/file/sixtp-dom-generators.h @@ -31,11 +31,11 @@ #include "gnc-xml-helper.h" #include "sixtp-dom-generators.h" -#include "GNCId.h" #include "gnc-commodity.h" #include "gnc-date.h" #include "gnc-numeric.h" #include "kvp_frame.h" +#include "qofid.h" xmlNodePtr text_to_dom_tree(const char *tag, const char *str); xmlNodePtr int_to_dom_tree(const char *tag, gint64 val); diff --git a/src/backend/file/sixtp-dom-parsers.c b/src/backend/file/sixtp-dom-parsers.c index 7b4c65325a..895fe64e3a 100644 --- a/src/backend/file/sixtp-dom-parsers.c +++ b/src/backend/file/sixtp-dom-parsers.c @@ -30,10 +30,10 @@ #include "gnc-engine-util.h" #include "gnc-commodity.h" #include "gnc-engine.h" +#include "qofid.h" #include "sixtp-utils.h" #include "sixtp-dom-parsers.h" -#include "GNCId.h" static short module = MOD_IO; diff --git a/src/backend/file/sixtp-dom-parsers.h b/src/backend/file/sixtp-dom-parsers.h index 1f0f13bd93..4a5377caa4 100644 --- a/src/backend/file/sixtp-dom-parsers.h +++ b/src/backend/file/sixtp-dom-parsers.h @@ -31,11 +31,11 @@ #include "gnc-xml-helper.h" #include "FreqSpec.h" -#include "GNCId.h" -#include "gnc-book.h" #include "gnc-commodity.h" #include "gnc-date.h" #include "kvp_frame.h" +#include "qofbook.h" +#include "qofid.h" GUID* dom_tree_to_guid(xmlNodePtr node); diff --git a/src/backend/file/test/test-file-stuff.c b/src/backend/file/test/test-file-stuff.c index 3e9a19163b..e18ecf5d44 100644 --- a/src/backend/file/test/test-file-stuff.c +++ b/src/backend/file/test/test-file-stuff.c @@ -181,7 +181,7 @@ equals_node_val_vs_guid(xmlNodePtr node, const GUID *id) } gboolean -equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com, GNCBook *book) +equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com, QofBook *book) { gnc_commodity *cmpcom; @@ -301,7 +301,7 @@ grab_file_doc(const char *filename) static void test_load_file(const char *filename, gxpf_callback cb, sixtp *parser, const char *parser_tag, - GNCBook *book) + QofBook *book) { xmlNodePtr node; sixtp *main_parser; @@ -347,7 +347,7 @@ test_load_file(const char *filename, gxpf_callback cb, void test_files_in_dir(int argc, char **argv, gxpf_callback cb, sixtp *parser, const char *parser_tag, - GNCBook *book) + QofBook *book) { int count; diff --git a/src/backend/postgres/Makefile.am b/src/backend/postgres/Makefile.am index 8aa1ce13d5..b28e1ede60 100644 --- a/src/backend/postgres/Makefile.am +++ b/src/backend/postgres/Makefile.am @@ -102,10 +102,10 @@ AM_CFLAGS = \ $(M4_SRC): table.m4 -%-autogen.c: %-objects.m4 +%-autogen.c: %-objects.m4 table.m4 m4 -I ${srcdir} $< > $@ -%-autogen.h: %-objects-header.m4 +%-autogen.h: %-objects-header.m4 table.m4 m4 -I ${srcdir} $< > $@ .sql.c: diff --git a/src/backend/postgres/PostgresBackend.c b/src/backend/postgres/PostgresBackend.c index b45bc25637..c5b3dfd9e4 100644 --- a/src/backend/postgres/PostgresBackend.c +++ b/src/backend/postgres/PostgresBackend.c @@ -197,18 +197,38 @@ pgendSplitLookup (PGBackend *be, const GUID *split_guid) return NULL; } +struct _iter { + const GUID *guid; + QofEntity *ent; +}; + +static void +cforeach (QofCollection *col, gpointer data) +{ + struct _iter *iter = data; + if (iter->ent) return; + iter->ent = qof_collection_lookup_entity (col, iter->guid); +} + QofIdType pgendGUIDType (PGBackend *be, const GUID *guid) { GList *node; - QofIdType tip = GNC_ID_NONE; + struct _iter iter; + + iter.guid = guid; + iter.ent = NULL; ENTER("guid = %s", guid_to_string(guid)); for (node=be->blist; node; node=node->next) { QofBook *book = node->data; - tip = qof_entity_type (qof_book_get_entity_table(book), guid); - if (GNC_ID_NONE != tip) { LEAVE("tip = %s", tip); return tip; } + qof_book_foreach_collection (book, cforeach, &iter); + if (iter.ent) + { + LEAVE("tip = %s", iter.ent->e_type); + return iter.ent->e_type; + } } LEAVE("tip = NULL"); @@ -559,7 +579,7 @@ pgendFillOutToCheckpoint (PGBackend *be, const char *query_string) Transaction *trans = (Transaction *) node->data; GList *engine_splits, *snode; - trans->kvp_data = pgendKVPFetch (be, trans->idata, trans->kvp_data); + trans->inst.kvp_data = pgendKVPFetch (be, trans->idata, trans->inst.kvp_data); engine_splits = xaccTransGetSplitList(trans); for (snode = engine_splits; snode; snode=snode->next) @@ -911,7 +931,7 @@ pgendSync (QofBackend *bend, QofBook *book) /* hack alert -- In some deranged theory, we should be * syncing prices here, as well as syncing any/all other * engine structures that need to be stored. But instead, - * price syn is handled as a separate routine ... + * price sync is handled as a separate routine ... */ /* re-enable events */ diff --git a/src/backend/postgres/README b/src/backend/postgres/README index 51be0aace1..d5ac2cacdf 100644 --- a/src/backend/postgres/README +++ b/src/backend/postgres/README @@ -1,11 +1,43 @@ -This directory contains code for SQL/Postgres support. The -SQL backend allows multiple users to view/edit the same data -at the same time, as well as allowing a single user to -keep data in an SQL database. This code is 'beta': it seems -to work, but really has not been heavily tested by lots -of users, and may still contain bugs. See also the -'to be done' list at the bottom. + GnuCash SQL/Postgres Support/HOWTO + ---------------------------------- + +This directory contains code for SQL/Postgres support. + +The SQL backend allows multiple users to view/edit the same data +at the same time, as well as allowing a single user to keep data +in an SQL database. + + +Status +------ +The SQL code has been "finished" for many years, and hasn't been +in recent active development. This means that the current SQL +backend does not support some of the newer GnuCash features; +in particular, it doesn't support the business objects needed for +the business accounting. It also doesn't currently support +scheduled/recurring transactions. Although the development is +currently dormant, we believe that it may heat up real soon, +since there is a core group of developers who are interested +in making SQL the default for all future versions of GnuCash. + +As long as development is dormant, note that you may not get +prompt support on the mailing list, and, if you find bugs, they +might not be fixed quickly. + +Currently, only Postgres is supported, but other databases are +planned. See also the 'to be done' list at the bottom for more +detail. + +Table of Contents +----------------- +-- Postgres Install Instructions +-- GnuCash Build Instructions +-- How To Use GnuCash with Postgres +-- Remote Access +-- Access Modes +-- Performance +-- ToDo List Postgres Install Instructions @@ -13,9 +45,9 @@ Postgres Install Instructions 1) Install PostgresSQL server, client and devel packages. (Both the 6.x and the 7.x versions of Postgres should work). -2) if installed from redhat, then running /etc/rc.d/init.d/postgresql +2) If installed from RedHat, then running /etc/rc.d/init.d/postgresql will setup and initialize basic Postgres first-time setup & config. -3) as root, 'su - postgres' then run 'createuser' to add your user id +3) As root, 'su - postgres' then run 'createuser' to add your user id (don't set a password on your postgres db name, yet, GnuCash doesn't have a GUI to ask for your password yet) If you've forgotten what users are on the system, you can check @@ -76,45 +108,49 @@ Same as usual, but you must specify the flag '--enable-sql' in order to build in Postgres support. i.e. ./configure --enable-sql -and then 'make'. +and then 'make' and then 'make install' -How To Use This Thing ---------------------- +How To Use GnuCash with Postgres +-------------------------------- a) Open your favorite datafile in the usual fashion. b) Click on 'Save As' -c) enter the following URL instead of a filename in the file picker: +c) Enter the following URL instead of a filename in the file picker: postgres://localhost/some_dbname_you_pick The above steps will copy your data into that database. You can then restart gnucash (or keep working) and type in the same URL in the file open dialogs. Or try it on the command line: -/usr/local/bin/gnucash postgres://localhost/dbname_whatever +home:~ $ gnucash postgres://localhost/dbname_whatever Note: GnuCash will automatically create the database if it does not already exist. Do *not* try to create the database by hand, or to specify a database that wasn't created by GnuCash. -Warning: the postgres backend is in active development, -and occasionally the database format changes in a way that is -not backwards compatible. If you have data that you want to -move from older to newer versions, you can do the following: --- start up older version of gnucash, open your postgres://... - URL. --- 'save as' to an ordinary gnucash file (its a flat XML file) --- exit the program. --- start the newer version of gnucash, open the XML file. --- 'save as' a new postgres database. (be sure to pick a new name). - +You can also "copy" from the SQL database to an XML file. +If you don't trust the SQL backend, this might be a good way to +backup your data. To do this: + +a) Open the SQL database in "single user mode": + postgres://localhost/dbname_whatever?mode=single-update + It is important to specify the single-user mode + (if you don't, not all of your data will be saved to the file) +b) Click on 'Save As' and enter an ordinary file name. + +We promise that future versions of GnuCash will be backwards +compatible with the current SQL database layout. There is a +specific upgrade module designed into the system that handles +version upgrades. + Remote Access ------------- In principle, you can use URL's such as: postgres://some.where.com/dbname However, these URL's require that the host 'some.where.com' have -TCPIP access enabled (by following instructions (6) above). -This is true even if the hostname is your local machine. Thus, +TCPIP access enabled (by following the postgres install instruction (6) +above). This is true even if the hostname is your local machine. Thus, unless you've setup Postgres TCPIP connections, you *MUST* use URL's of the form postgres://localhost/dbname @@ -209,7 +245,7 @@ probably fix any weird account balances you are seeing. a test case that can reliably recreate these, you should submit a bug report). -(Note to developers: think of this as an fsck: balances +(Note to developers: think of this as a safe fsck: balances shouldn't get wacky, but if you've been running a long time and something weird has happened, then a periodic cleanup is good to have. Maybe this should be automated ...) @@ -261,9 +297,27 @@ To Be Done ---------- Core bugs/features that still need work: -(none in this list are truly critical at this point, except possibly +High Priority: +-------------- +Currently, the database backend is completely missing support for +"lots", and thus cannot support capital gains computations. It is +also missing support for business objects. + +-- remove the bogus 'price query' call in the backend, change it to + use the qof query infrastructure. + +-- port to use SQLLite as a possible backend. Will need to abandon + balance checkpoints to do this. + + +Medium/Low Priority Work: +------------------------- +Nothing in this list is truly critical at this point, except possibly the username/password dialog, and its effect with regards to initial db -access). +access. + +-- port to use libdbi bindings, instead of the postgres native + call interface. This should be easy. -- Wire in the GUI to ask user for username/password to log onto the server. (GUI already implemented, just not yet used). diff --git a/src/backend/postgres/account.c b/src/backend/postgres/account.c index e9b7c285f6..2b194fb661 100644 --- a/src/backend/postgres/account.c +++ b/src/backend/postgres/account.c @@ -92,7 +92,7 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct, const gnc_commodity *com; if (!be || !acct) return; - if ((FALSE == do_mark) && (FALSE == acct->core_dirty)) return; + if ((FALSE == do_mark) && (FALSE == acct->inst.dirty)) return; ENTER ("acct=%p, mark=%d", acct, do_mark); @@ -139,7 +139,7 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct, if (acct->idata) { pgendKVPDelete (be, acct->idata); - pgendKVPStore (be, acct->idata, acct->kvp_data); + pgendKVPStore (be, acct->idata, acct->inst.kvp_data); } LEAVE(" "); } @@ -227,7 +227,7 @@ restore_cb (Account *acc, void * cb_data) { PGBackend *be = (PGBackend *) cb_data; if (0 == acc->idata) return NULL; - acc->kvp_data = pgendKVPFetch (be, acc->idata, acc->kvp_data); + acc->inst.kvp_data = pgendKVPFetch (be, acc->idata, acc->inst.kvp_data); return NULL; } @@ -552,7 +552,7 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid) { if (acc->idata) { - acc->kvp_data = pgendKVPFetch (be, acc->idata, acc->kvp_data); + acc->inst.kvp_data = pgendKVPFetch (be, acc->idata, acc->inst.kvp_data); } acc->version_check = be->version_check; @@ -585,7 +585,7 @@ pgend_account_commit_edit (QofBackend * bend, ENTER ("be=%p, acct=%p", be, acct); if (!be || !acct) return; - if (FALSE == acct->core_dirty) + if (FALSE == acct->inst.dirty) { parent = xaccAccountGetParent(acct); if (parent) parent->saved = 1; @@ -607,7 +607,7 @@ pgend_account_commit_edit (QofBackend * bend, * made changes, and we must roll back. */ if (0 < pgendAccountCompareVersion (be, acct)) { - acct->do_free = FALSE; + acct->inst.do_free = FALSE; p = "ROLLBACK;"; SEND_QUERY (be,p,); FINISH_QUERY(be->connection); @@ -624,7 +624,7 @@ pgend_account_commit_edit (QofBackend * bend, acct->version ++; /* be sure to update the version !! */ acct->version_check = be->version_check; - if (acct->do_free) + if (acct->inst.do_free) { const GUID *guid = xaccAccountGetGUID(acct); pgendKVPDelete (be, acct->idata); diff --git a/src/backend/postgres/book.c b/src/backend/postgres/book.c index 98b09cdc06..e3839f45b4 100644 --- a/src/backend/postgres/book.c +++ b/src/backend/postgres/book.c @@ -145,7 +145,7 @@ get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) guid = nullguid; /* just in case the read fails ... */ string_to_guid (DB_GET_VAL("bookGuid",j), &guid); - qof_book_set_guid (book, guid); + qof_book_set_guid (book, &guid); book->book_open = (DB_GET_VAL("book_open",j))[0]; book->version = atoi(DB_GET_VAL("version",j)); @@ -200,14 +200,14 @@ get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data) for (node=blist; node; node=node->next) { book = node->data; - if (guid_equal (&book->guid, &guid)) break; + if (guid_equal (&book->entity.guid, &guid)) break; book = NULL; } if (!book) { book = qof_book_new(); - qof_book_set_guid (book, guid); + qof_book_set_guid (book, &guid); } book->book_open = (DB_GET_VAL("book_open",j))[0]; diff --git a/src/backend/postgres/gncquery.c b/src/backend/postgres/gncquery.c index edd3d2585a..5169445da6 100644 --- a/src/backend/postgres/gncquery.c +++ b/src/backend/postgres/gncquery.c @@ -49,7 +49,7 @@ #include "qofquery.h" #include "qofquery-p.h" #include "qofquerycore-p.h" -#include "qofqueryobject.h" +#include "qofclass.h" #include "gncquery.h" #include "builder.h" @@ -755,13 +755,13 @@ sqlQuery_build(sqlQuery * sq, Query * q) } else if (!safe_strcmp(path->data, SPLIT_VALUE)) { need_entry = TRUE; need_trans_commodity = TRUE; - } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_GUID)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID)) { if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID)) need_entry = TRUE; else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) { need_account = TRUE; } - } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_KVP)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP)) { if (!safe_strcmp(path->data, SPLIT_KVP)) need_entry = TRUE; else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) @@ -855,12 +855,12 @@ sqlQuery_build(sqlQuery * sq, Query * q) path = qof_query_term_get_param_path(qt); invert = qof_query_term_is_inverted(qt); - if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_GUID)) { + if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID)) { query_guid_t pdata = (query_guid_t) pd; GList *node; char *field = NULL; - PINFO("term is QOF_QUERYCORE_GUID"); + PINFO("term is QOF_TYPE_GUID"); if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID)) { field = "gncSplit.splitGuid"; @@ -959,7 +959,7 @@ sqlQuery_build(sqlQuery * sq, Query * q) more_and = 0; } - } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_STRING)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING)) { query_string_t pdata = (query_string_t) pd; if (!safe_strcmp(path->data, SPLIT_ACTION)) { @@ -991,7 +991,7 @@ sqlQuery_build(sqlQuery * sq, Query * q) (char *)(path->data)); - } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_NUMERIC)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_NUMERIC)) { query_numeric_t pdata = (query_numeric_t) pd; @@ -1022,7 +1022,7 @@ sqlQuery_build(sqlQuery * sq, Query * q) PINFO("Unknown NUMERIC: %s", (char *)(path->data)); } - } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_DATE)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_DATE)) { query_date_t pdata = (query_date_t) pd; char *field = NULL; const char *op = NULL; @@ -1049,7 +1049,7 @@ sqlQuery_build(sqlQuery * sq, Query * q) if (invert) sq->pq = stpcpy(sq->pq, ") "); - } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_CHAR)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_CHAR)) { query_char_t pdata = (query_char_t) pd; int got_one = 0; @@ -1076,7 +1076,7 @@ sqlQuery_build(sqlQuery * sq, Query * q) } else PINFO("Unknown CHAR type, %s", (char *)(path->data)); - } else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_KVP)) { + } else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP)) { query_kvp_t pdata = (query_kvp_t) pd; PINFO("term is a KVP"); diff --git a/src/backend/postgres/price.c b/src/backend/postgres/price.c index e723689dd1..c5b306f3a5 100644 --- a/src/backend/postgres/price.c +++ b/src/backend/postgres/price.c @@ -489,7 +489,7 @@ pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr) * made changes, and we must roll back. */ if (0 < pgendPriceCompareVersion (be, pr)) { - pr->do_free = FALSE; + pr->inst.do_free = FALSE; bufp = "ROLLBACK;"; SEND_QUERY (be,bufp,); FINISH_QUERY(be->connection); @@ -506,7 +506,7 @@ pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr) pr->version ++; /* be sure to update the version !! */ pr->version_check = be->version_check; - if (pr->do_free) + if (pr->inst.do_free) { pgendStoreAuditPrice (be, pr, SQL_DELETE); bufp = be->buff; *bufp = 0; diff --git a/src/backend/postgres/putil.h b/src/backend/postgres/putil.h index 2752a03826..107eb3c3f2 100644 --- a/src/backend/postgres/putil.h +++ b/src/backend/postgres/putil.h @@ -348,25 +348,25 @@ int finishQuery(PGBackend *be); /* --------------------------------------------------------------- */ -#define FIND_BOOK(book) { \ - if (NULL == book) \ - { \ - GList *node; \ - GUID book_guid; \ - \ - /* Find the book that holds this item */ \ - book_guid = nullguid; /* just in case the read fails */ \ - string_to_guid (DB_GET_VAL("bookGUID",j), &book_guid); \ - \ - book = NULL; \ - for (node=be->blist; node; node=node->next) \ - { \ - book = node->data; \ - if (guid_equal (&book->guid, &book_guid)) break; \ - book = NULL; \ - } \ - if (!book) return data; \ - } \ +#define FIND_BOOK(book) { \ + if (NULL == book) \ + { \ + GList *node; \ + GUID book_guid; \ + \ + /* Find the book that holds this item */ \ + book_guid = nullguid; /* just in case the read fails */ \ + string_to_guid (DB_GET_VAL("bookGUID",j), &book_guid); \ + \ + book = NULL; \ + for (node=be->blist; node; node=node->next) \ + { \ + book = node->data; \ + if (guid_equal (&book->entity.guid, &book_guid)) break; \ + book = NULL; \ + } \ + if (!book) return data; \ + } \ } diff --git a/src/backend/postgres/table.m4 b/src/backend/postgres/table.m4 index 1aec252872..a4f3c95b2b 100644 --- a/src/backend/postgres/table.m4 +++ b/src/backend/postgres/table.m4 @@ -362,7 +362,7 @@ define(`compare_version', p = be->buff; *p = 0; p = stpcpy (p, "SELECT version FROM tablename($@) WHERE key_fieldname($@) = ''`"); - p = guid_to_string_buff (&(ptr->guid), p); + p = guid_to_string_buff (qof_entity_get_guid(QOF_ENTITY(ptr)), p); p = stpcpy (p, "''`;"); SEND_QUERY (be,be->buff, -1); sql_version = (int) pgendGetResults (be, get_version_cb, (gpointer) -1); @@ -392,7 +392,7 @@ define(`is_deleted', p = be->buff; *p = 0; p = stpcpy (p, "SELECT version FROM tablename($@)" "Trail WHERE key_fieldname($@) = ''`"); - p = guid_to_string_buff (&(ptr->guid), p); + p = guid_to_string_buff (qof_entity_get_guid(QOF_ENTITY(ptr)), p); p = stpcpy (p, "''` AND change = ''`d''`;"); SEND_QUERY (be,be->buff, -1); sql_version = (int) pgendGetResults (be, get_version_cb, (gpointer) -1); diff --git a/src/backend/postgres/txn.c b/src/backend/postgres/txn.c index adc92d1c54..9ecdf653d1 100644 --- a/src/backend/postgres/txn.c +++ b/src/backend/postgres/txn.c @@ -178,7 +178,7 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, { Split *s = split_node->data; - if (s && guid_equal (&s->guid, &dti->guid)) + if (s && guid_equal (&s->entity.guid, &dti->guid)) { pgendStoreAuditSplit (be, s, SQL_DELETE); break; @@ -218,8 +218,8 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, /* Update the rest */ start = xaccTransGetSplitList(trans); - PINFO ("split-list=%p, do_free=%d", start, trans->do_free); - if ((start) && !(trans->do_free)) + PINFO ("split-list=%p, do_free=%d", start, trans->inst.do_free); + if ((start) && !(trans->inst.do_free)) { gnc_commodity *com; @@ -255,7 +255,7 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, if (trans->idata) { pgendKVPDelete (be, trans->idata); - pgendKVPStore (be, trans->idata, trans->kvp_data); + pgendKVPStore (be, trans->idata, trans->inst.kvp_data); } } else @@ -473,7 +473,7 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans) s = pgendSplitLookup (be, &guid); if (!s) { - s = xaccMallocSplit(trans->book); + s = xaccMallocSplit(trans->inst.book); xaccSplitSetGUID(s, &guid); } @@ -809,13 +809,13 @@ pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid) if (0 != trans->idata) { - if (!kvp_frame_is_empty (trans->kvp_data)) + if (!kvp_frame_is_empty (trans->inst.kvp_data)) { - kvp_frame_delete (trans->kvp_data); - trans->kvp_data = kvp_frame_new (); + kvp_frame_delete (trans->inst.kvp_data); + trans->inst.kvp_data = kvp_frame_new (); } - trans->kvp_data = pgendKVPFetch (be, trans->idata, trans->kvp_data); + trans->inst.kvp_data = pgendKVPFetch (be, trans->idata, trans->inst.kvp_data); } engine_splits = xaccTransGetSplitList(trans); @@ -1003,7 +1003,7 @@ pgend_trans_commit_edit (QofBackend * bend, "\ttransaction is '%s' %s\n", xaccTransGetDescription (trans), buf); rollback = 0; - trans->do_free = TRUE; + trans->inst.do_free = TRUE; } else { diff --git a/src/backend/postgres/txnmass.c b/src/backend/postgres/txnmass.c index cdee3d4acf..71b21654d2 100644 --- a/src/backend/postgres/txnmass.c +++ b/src/backend/postgres/txnmass.c @@ -269,7 +269,7 @@ pgendGetMassTransactions (PGBackend *be, QofBook *book) if (trans->idata) { - trans->kvp_data = pgendKVPFetch (be, trans->idata, trans->kvp_data); + trans->inst.kvp_data = pgendKVPFetch (be, trans->idata, trans->inst.kvp_data); } splits = xaccTransGetSplitList(trans); diff --git a/src/backend/rpc/RpcBackend.c b/src/backend/rpc/RpcBackend.c index 00e65081ba..a2c140d1e2 100644 --- a/src/backend/rpc/RpcBackend.c +++ b/src/backend/rpc/RpcBackend.c @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #define _GNU_SOURCE diff --git a/src/backend/rpc/RpcBackend.h b/src/backend/rpc/RpcBackend.h index 5de65d09f8..9d7c89bf22 100644 --- a/src/backend/rpc/RpcBackend.h +++ b/src/backend/rpc/RpcBackend.h @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef RPC_BACKEND_H diff --git a/src/backend/rpc/RpcServer.c b/src/backend/rpc/RpcServer.c index bb37476596..37e8207da9 100644 --- a/src/backend/rpc/RpcServer.c +++ b/src/backend/rpc/RpcServer.c @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #define _GNU_SOURCE diff --git a/src/backend/rpc/RpcServer.h b/src/backend/rpc/RpcServer.h index 5f9b7d3857..9eeeb91bcd 100644 --- a/src/backend/rpc/RpcServer.h +++ b/src/backend/rpc/RpcServer.h @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef RPC_SERVER_H diff --git a/src/backend/rpc/RpcServerP.h b/src/backend/rpc/RpcServerP.h index 1d43f694aa..f1e9d1169d 100644 --- a/src/backend/rpc/RpcServerP.h +++ b/src/backend/rpc/RpcServerP.h @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef RPC_SERVERP_H diff --git a/src/backend/rpc/RpcSock.c b/src/backend/rpc/RpcSock.c index c3195cb1e4..a3f08295d9 100644 --- a/src/backend/rpc/RpcSock.c +++ b/src/backend/rpc/RpcSock.c @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #include diff --git a/src/backend/rpc/RpcSock.h b/src/backend/rpc/RpcSock.h index 163b9924ab..ae6038de58 100644 --- a/src/backend/rpc/RpcSock.h +++ b/src/backend/rpc/RpcSock.h @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef RPC_SOCK_H diff --git a/src/backend/rpc/RpcUtils.c b/src/backend/rpc/RpcUtils.c index 93696fc576..ae0af5c55c 100644 --- a/src/backend/rpc/RpcUtils.c +++ b/src/backend/rpc/RpcUtils.c @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #include "RpcUtils.h" diff --git a/src/backend/rpc/RpcUtils.h b/src/backend/rpc/RpcUtils.h index a51778845c..71c77c79f3 100644 --- a/src/backend/rpc/RpcUtils.h +++ b/src/backend/rpc/RpcUtils.h @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef RPC_UTILS_H diff --git a/src/backend/rpc/gncAccount.x b/src/backend/rpc/gncAccount.x index 8dd1deebc7..815a8e2aec 100644 --- a/src/backend/rpc/gncAccount.x +++ b/src/backend/rpc/gncAccount.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_ACCOUNT_X diff --git a/src/backend/rpc/gncCommodity.x b/src/backend/rpc/gncCommodity.x index 8dcc2a0c33..63419866a0 100644 --- a/src/backend/rpc/gncCommodity.x +++ b/src/backend/rpc/gncCommodity.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_COMMODITY_X diff --git a/src/backend/rpc/gncGUID.x b/src/backend/rpc/gncGUID.x index ec60259d95..6a7589304d 100644 --- a/src/backend/rpc/gncGUID.x +++ b/src/backend/rpc/gncGUID.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_GUID_X diff --git a/src/backend/rpc/gncKVP.x b/src/backend/rpc/gncKVP.x index 6c238d1d26..eab4981a2c 100644 --- a/src/backend/rpc/gncKVP.x +++ b/src/backend/rpc/gncKVP.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_KVP_X diff --git a/src/backend/rpc/gncPrice.x b/src/backend/rpc/gncPrice.x index 0779fedf84..d1efd2c3a7 100644 --- a/src/backend/rpc/gncPrice.x +++ b/src/backend/rpc/gncPrice.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_PRICE_X diff --git a/src/backend/rpc/gncQuery.x b/src/backend/rpc/gncQuery.x index 97ce369419..6a7e883d2c 100644 --- a/src/backend/rpc/gncQuery.x +++ b/src/backend/rpc/gncQuery.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_QUERY_X diff --git a/src/backend/rpc/gncRpc.x b/src/backend/rpc/gncRpc.x index 3d4f266016..973d9543ad 100644 --- a/src/backend/rpc/gncRpc.x +++ b/src/backend/rpc/gncRpc.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifdef RPC_XDR diff --git a/src/backend/rpc/gncRpc_server.c b/src/backend/rpc/gncRpc_server.c index 5d94b8a0d1..d07427938b 100644 --- a/src/backend/rpc/gncRpc_server.c +++ b/src/backend/rpc/gncRpc_server.c @@ -11,6 +11,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #include "gncRpc.h" diff --git a/src/backend/rpc/gncSplit.x b/src/backend/rpc/gncSplit.x index 24fbec8ca6..2d3a565c7c 100644 --- a/src/backend/rpc/gncSplit.x +++ b/src/backend/rpc/gncSplit.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_SPLIT_X diff --git a/src/backend/rpc/gncTxn.x b/src/backend/rpc/gncTxn.x index 2d6729169b..b9575dfa2b 100644 --- a/src/backend/rpc/gncTxn.x +++ b/src/backend/rpc/gncTxn.x @@ -8,6 +8,23 @@ * HISTORY: * Created By: Derek Atkins * Copyright (c) 2001, Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef __GNC_TXN_X diff --git a/src/backend/rpc/xprt_thrd.c b/src/backend/rpc/xprt_thrd.c index 43b2b1ccb2..94b62c086b 100644 --- a/src/backend/rpc/xprt_thrd.c +++ b/src/backend/rpc/xprt_thrd.c @@ -7,7 +7,24 @@ * received. * * Created by: Derek Atkins + * Copyright (c) 2001 Derek Atkins * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #include diff --git a/src/backend/rpc/xprt_thrd.h b/src/backend/rpc/xprt_thrd.h index 3ff395d58e..ee29c60534 100644 --- a/src/backend/rpc/xprt_thrd.h +++ b/src/backend/rpc/xprt_thrd.h @@ -9,7 +9,24 @@ * received. * * Created by: Derek Atkins + * Copyright (c) 2001 Derek Atkins * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef RPC_XPRT_THRD_H diff --git a/src/business/business-core/businessmod-core.c b/src/business/business-core/businessmod-core.c index 9adfdd405a..84d536dc44 100644 --- a/src/business/business-core/businessmod-core.c +++ b/src/business/business-core/businessmod-core.c @@ -3,6 +3,24 @@ * module definition/initialization for the core Business module * * Copyright (c) 2001 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org + * *********************************************************************/ #include "config.h" diff --git a/src/business/business-core/file/gnc-address-xml-v2.h b/src/business/business-core/file/gnc-address-xml-v2.h index 1cfbdb1aa5..9a97a6de1e 100644 --- a/src/business/business-core/file/gnc-address-xml-v2.h +++ b/src/business/business-core/file/gnc-address-xml-v2.h @@ -1,6 +1,23 @@ /* gnc-address-xml-v2.h -- Address XML header * * Copyright (C) 2002 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_ADDRESS_XML_V2_H diff --git a/src/business/business-core/file/gnc-bill-term-xml-v2.c b/src/business/business-core/file/gnc-bill-term-xml-v2.c index 98176315b3..6592b6c81d 100644 --- a/src/business/business-core/file/gnc-bill-term-xml-v2.c +++ b/src/business/business-core/file/gnc-bill-term-xml-v2.c @@ -42,13 +42,16 @@ #include "io-gncxml-v2.h" #include "gncBillTermP.h" +#include "gncInvoice.h" #include "gnc-bill-term-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" -#include "gncInvoice.h" +#include "qofinstance.h" +#include "qofobject.h" -#define _GNC_MOD_NAME GNC_BILLTERM_MODULE_NAME +#include "xml-helpers.h" + +#define _GNC_MOD_NAME GNC_ID_BILLTERM static short module = MOD_IO; @@ -76,36 +79,15 @@ const gchar *billterm_version_string = "2.0.0"; #define prox_discount_string "bt-prox:discount" #define prox_cutoff_string "bt-prox:cutoff-day" -static void -maybe_add_guid (xmlNodePtr ptr, const char *tag, GncBillTerm *term) -{ - if (term) - xmlAddChild (ptr, guid_to_dom_tree (tag, gncBillTermGetGUID (term))); -} - -static void -maybe_add_int (xmlNodePtr ptr, const char *tag, gint val) -{ - if (val) - xmlAddChild (ptr, int_to_dom_tree (tag, val)); -} - -static void -maybe_add_numeric (xmlNodePtr ptr, const char *tag, gnc_numeric val) -{ - if (!gnc_numeric_zero_p (val)) - xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &val)); -} - static xmlNodePtr billterm_dom_tree_create (GncBillTerm *term) { - xmlNodePtr ret, data; + xmlNodePtr ret, data, kvpnode; ret = xmlNewNode(NULL, gnc_billterm_string); xmlSetProp(ret, "version", billterm_version_string); - maybe_add_guid(ret, billterm_guid_string, term); + maybe_add_guid(ret, billterm_guid_string, QOF_INSTANCE(term)); xmlAddChild(ret, text_to_dom_tree (billterm_name_string, gncBillTermGetName (term))); xmlAddChild(ret, text_to_dom_tree (billterm_desc_string, @@ -116,11 +98,18 @@ billterm_dom_tree_create (GncBillTerm *term) xmlAddChild(ret, int_to_dom_tree (billterm_invisible_string, gncBillTermGetInvisible (term))); + kvpnode = kvp_frame_to_dom_tree (billterm_slots_string, + qof_instance_get_slots (QOF_INSTANCE(term))); + if (kvpnode) xmlAddChild (ret, kvpnode); + + /* We should not be our own child */ if (gncBillTermGetChild(term) != term) - maybe_add_guid(ret, billterm_child_string, gncBillTermGetChild (term)); + maybe_add_guid(ret, billterm_child_string, + QOF_INSTANCE(gncBillTermGetChild (term))); - maybe_add_guid(ret, billterm_parent_string, gncBillTermGetParent (term)); + maybe_add_guid(ret, billterm_parent_string, + QOF_INSTANCE(gncBillTermGetParent (term))); switch (gncBillTermGetType (term)) { case GNC_TERM_TYPE_DAYS: @@ -407,7 +396,9 @@ billterm_prox_data_handler (xmlNodePtr node, gpointer billterm_pdata) static gboolean billterm_slots_handler (xmlNodePtr node, gpointer billterm_pdata) { - return TRUE; + struct billterm_pdata *pdata = billterm_pdata; + return dom_tree_to_kvp_frame_given (node, + qof_instance_get_slots (QOF_INSTANCE(pdata->term))); } static struct dom_tree_handler billterm_handlers_v2[] = { @@ -494,7 +485,7 @@ billterm_sixtp_parser_create(void) } static void -do_count (gpointer term_p, gpointer count_p) +do_count (QofEntity *term_p, gpointer count_p) { int *count = count_p; (*count)++; @@ -504,15 +495,15 @@ static int billterm_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_billterm (gpointer term_p, gpointer out_p) +xml_add_billterm (QofEntity *term_p, gpointer out_p) { xmlNodePtr node; - GncBillTerm *term = term_p; + GncBillTerm *term = (GncBillTerm *) term_p; FILE *out = out_p; node = billterm_dom_tree_create (term); @@ -524,7 +515,7 @@ xml_add_billterm (gpointer term_p, gpointer out_p) static void billterm_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_billterm, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_billterm, (gpointer) out); } static gboolean @@ -568,9 +559,9 @@ billterm_find_senior (GncBillTerm *term) /* build a list of bill terms that are grandchildren or bogus (empty entry list). */ static void -billterm_scrub_cb (gpointer term_p, gpointer list_p) +billterm_scrub_cb (QofEntity *term_p, gpointer list_p) { - GncBillTerm *term = term_p; + GncBillTerm *term = GNC_BILLTERM(term_p); GList **list = list_p; if (billterm_is_grandchild(term)) { @@ -581,7 +572,7 @@ billterm_scrub_cb (gpointer term_p, gpointer list_p) if (t) { /* Fix up the broken "copy" function */ PWARN("Fixing broken child billterm: %s", - guid_to_string(gncBillTermGetGUID(term))); + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); gncBillTermBeginEdit(term); gncBillTermSetType(term, gncBillTermGetType(t)); @@ -602,10 +593,10 @@ billterm_scrub_cb (gpointer term_p, gpointer list_p) * grandchildren, then fix them to point to the most senior child */ static void -billterm_scrub_invoices (gpointer invoice_p, gpointer ht_p) +billterm_scrub_invoices (QofEntity * invoice_p, gpointer ht_p) { GHashTable *ht = ht_p; - GncInvoice *invoice = invoice_p; + GncInvoice *invoice = GNC_INVOICE(invoice_p); GncBillTerm *term, *new_bt; gint32 count; @@ -613,7 +604,7 @@ billterm_scrub_invoices (gpointer invoice_p, gpointer ht_p) if (term) { if (billterm_is_grandchild(term)) { PWARN("Fixing i-billterm on invoice %s\n", - guid_to_string(gncInvoiceGetGUID(invoice))); + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(invoice)))); new_bt = billterm_find_senior(term); gncInvoiceBeginEdit(invoice); gncInvoiceSetTerms(invoice, new_bt); @@ -629,10 +620,10 @@ billterm_scrub_invoices (gpointer invoice_p, gpointer ht_p) } static void -billterm_scrub_cust (gpointer cust_p, gpointer ht_p) +billterm_scrub_cust (QofEntity * cust_p, gpointer ht_p) { GHashTable *ht = ht_p; - GncCustomer *cust = cust_p; + GncCustomer *cust = GNC_CUSTOMER(cust_p); GncBillTerm *term; gint32 count; @@ -645,10 +636,10 @@ billterm_scrub_cust (gpointer cust_p, gpointer ht_p) } static void -billterm_scrub_vendor (gpointer vendor_p, gpointer ht_p) +billterm_scrub_vendor (QofEntity * vendor_p, gpointer ht_p) { GHashTable *ht = ht_p; - GncVendor *vendor = vendor_p; + GncVendor *vendor = GNC_VENDOR(vendor_p); GncBillTerm *term; gint32 count; @@ -668,7 +659,7 @@ billterm_reset_refcount (gpointer key, gpointer value, gpointer notused) if (count != gncBillTermGetRefcount(term) && !gncBillTermGetInvisible(term)) { PWARN("Fixing refcount on billterm %s (%lld -> %d)\n", - guid_to_string(gncBillTermGetGUID(term)), + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))), gncBillTermGetRefcount(term), count) gncBillTermSetRefcount(term, count); } @@ -682,17 +673,17 @@ billterm_scrub (GNCBook *book) GncBillTerm *parent, *term; GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); - gncObjectForeach (GNC_INVOICE_MODULE_NAME, book, billterm_scrub_invoices, ht); - gncObjectForeach (GNC_CUSTOMER_MODULE_NAME, book, billterm_scrub_cust, ht); - gncObjectForeach (GNC_VENDOR_MODULE_NAME, book, billterm_scrub_vendor, ht); - gncObjectForeach (_GNC_MOD_NAME, book, billterm_scrub_cb, &list); + qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht); + qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht); + qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht); + qof_object_foreach (GNC_ID_BILLTERM, book, billterm_scrub_cb, &list); /* destroy the list of "grandchildren" bill terms */ for (node = list; node; node = node->next) { term = node->data; PINFO ("deleting grandchild billterm: %s\n", - guid_to_string(gncBillTermGetGUID(term))); + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); /* Make sure the parent has no children */ parent = gncBillTermGetParent(term); @@ -723,7 +714,7 @@ gnc_billterm_xml_initialize (void) billterm_scrub, }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-bill-term-xml-v2.h b/src/business/business-core/file/gnc-bill-term-xml-v2.h index 401ada6d58..38e3cfa652 100644 --- a/src/business/business-core/file/gnc-bill-term-xml-v2.h +++ b/src/business/business-core/file/gnc-bill-term-xml-v2.h @@ -2,6 +2,23 @@ * gnc-bill-term-xml-v2.h -- billing term xml i/o parser/unparsers * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_BILLTERM_XML_V2_H diff --git a/src/business/business-core/file/gnc-customer-xml-v2.c b/src/business/business-core/file/gnc-customer-xml-v2.c index 2a3968bb8a..c76583082c 100644 --- a/src/business/business-core/file/gnc-customer-xml-v2.c +++ b/src/business/business-core/file/gnc-customer-xml-v2.c @@ -48,9 +48,12 @@ #include "gnc-address-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" +#include "qofobject.h" +#include "qofinstance.h" -#define _GNC_MOD_NAME GNC_CUSTOMER_MODULE_NAME +#include "xml-helpers.h" + +#define _GNC_MOD_NAME GNC_ID_CUSTOMER static short module = MOD_IO; @@ -74,17 +77,10 @@ const gchar *customer_version_string = "2.0.0"; #define cust_taxtableoverride_string "cust:use-tt" #define cust_slots_string "cust:slots" -static void -maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) -{ - if (str && strlen(str) > 0) - xmlAddChild (ptr, text_to_dom_tree (tag, str)); -} - static xmlNodePtr customer_dom_tree_create (GncCustomer *cust) { - xmlNodePtr ret; + xmlNodePtr ret, kvpnode; gnc_numeric num; GncBillTerm *term; GncTaxTable *taxtable; @@ -93,7 +89,7 @@ customer_dom_tree_create (GncCustomer *cust) xmlSetProp(ret, "version", customer_version_string); xmlAddChild(ret, guid_to_dom_tree(cust_guid_string, - gncCustomerGetGUID (cust))); + qof_instance_get_guid(QOF_INSTANCE(cust)))); xmlAddChild(ret, text_to_dom_tree(cust_name_string, gncCustomerGetName (cust))); @@ -112,7 +108,7 @@ customer_dom_tree_create (GncCustomer *cust) term = gncCustomerGetTerms (cust); if (term) xmlAddChild(ret, guid_to_dom_tree(cust_terms_string, - gncBillTermGetGUID (term))); + qof_instance_get_guid (QOF_INSTANCE(term)))); xmlAddChild(ret, text_to_dom_tree(cust_taxincluded_string, gncTaxIncludedTypeToString ( @@ -137,7 +133,11 @@ customer_dom_tree_create (GncCustomer *cust) taxtable = gncCustomerGetTaxTable (cust); if (taxtable) xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string, - gncTaxTableGetGUID (taxtable))); + qof_instance_get_guid(QOF_INSTANCE(taxtable)))); + + kvpnode = kvp_frame_to_dom_tree (cust_slots_string, + qof_instance_get_slots (QOF_INSTANCE(cust))); + if (kvpnode) xmlAddChild (ret, kvpnode); return ret; } @@ -371,7 +371,9 @@ customer_taxtableoverride_handler (xmlNodePtr node, gpointer cust_pdata) static gboolean customer_slots_handler (xmlNodePtr node, gpointer cust_pdata) { - return TRUE; + struct customer_pdata *pdata = cust_pdata; + return dom_tree_to_kvp_frame_given (node, + qof_instance_get_slots (QOF_INSTANCE(pdata->customer))); } static struct dom_tree_handler customer_handlers_v2[] = { @@ -478,10 +480,10 @@ customer_should_be_saved (GncCustomer *customer) } static void -do_count (gpointer cust_p, gpointer count_p) +do_count (QofEntity * cust_p, gpointer count_p) { int *count = count_p; - if (customer_should_be_saved (cust_p)) + if (customer_should_be_saved ((GncCustomer *)cust_p)) (*count)++; } @@ -489,18 +491,18 @@ static int customer_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_customer (gpointer cust_p, gpointer out_p) +xml_add_customer (QofEntity * cust_p, gpointer out_p) { xmlNodePtr node; - GncCustomer *cust = cust_p; + GncCustomer *cust = (GncCustomer *) cust_p; FILE *out = out_p; - if (!customer_should_be_saved (cust_p)) + if (!customer_should_be_saved (cust)) return; node = customer_dom_tree_create (cust); @@ -512,7 +514,7 @@ xml_add_customer (gpointer cust_p, gpointer out_p) static void customer_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_customer, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_customer, (gpointer) out); } void @@ -528,7 +530,7 @@ gnc_customer_xml_initialize (void) NULL, /* scrub */ }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-customer-xml-v2.h b/src/business/business-core/file/gnc-customer-xml-v2.h index abb3990b9a..b263d6c40e 100644 --- a/src/business/business-core/file/gnc-customer-xml-v2.h +++ b/src/business/business-core/file/gnc-customer-xml-v2.h @@ -2,6 +2,23 @@ * gnc-customer-xml-v2.h -- customer xml i/o parser/unparser * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_CUSTOMER_XML_V2_H diff --git a/src/business/business-core/file/gnc-employee-xml-v2.c b/src/business/business-core/file/gnc-employee-xml-v2.c index 4b6de14359..a125398c67 100644 --- a/src/business/business-core/file/gnc-employee-xml-v2.c +++ b/src/business/business-core/file/gnc-employee-xml-v2.c @@ -46,9 +46,10 @@ #include "gnc-address-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" +#include "qofinstance.h" +#include "qofobject.h" -#define _GNC_MOD_NAME GNC_EMPLOYEE_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_EMPLOYEE static short module = MOD_IO; @@ -87,7 +88,7 @@ employee_dom_tree_create (GncEmployee *employee) xmlSetProp(ret, "version", employee_version_string); xmlAddChild(ret, guid_to_dom_tree(employee_guid_string, - gncEmployeeGetGUID (employee))); + qof_instance_get_guid(QOF_INSTANCE (employee)))); xmlAddChild(ret, text_to_dom_tree(employee_username_string, gncEmployeeGetUsername (employee))); @@ -119,7 +120,7 @@ employee_dom_tree_create (GncEmployee *employee) ccard_acc = gncEmployeeGetCCard (employee); if (ccard_acc) xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string, - xaccAccountGetGUID (ccard_acc))); + qof_instance_get_guid(QOF_INSTANCE(ccard_acc)))); return ret; } @@ -392,10 +393,10 @@ employee_should_be_saved (GncEmployee *employee) } static void -do_count (gpointer employee_p, gpointer count_p) +do_count (QofEntity * employee_p, gpointer count_p) { int *count = count_p; - if (employee_should_be_saved (employee_p)) + if (employee_should_be_saved ((GncEmployee *) employee_p)) (*count)++; } @@ -403,15 +404,15 @@ static int employee_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_employee (gpointer employee_p, gpointer out_p) +xml_add_employee (QofEntity * employee_p, gpointer out_p) { xmlNodePtr node; - GncEmployee *employee = employee_p; + GncEmployee *employee = (GncEmployee *) employee_p; FILE *out = out_p; if (!employee_should_be_saved (employee)) @@ -426,7 +427,7 @@ xml_add_employee (gpointer employee_p, gpointer out_p) static void employee_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_employee, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_employee, (gpointer) out); } void @@ -442,7 +443,7 @@ gnc_employee_xml_initialize (void) NULL, /* scrub */ }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-employee-xml-v2.h b/src/business/business-core/file/gnc-employee-xml-v2.h index 75fd301439..d70ebb6d02 100644 --- a/src/business/business-core/file/gnc-employee-xml-v2.h +++ b/src/business/business-core/file/gnc-employee-xml-v2.h @@ -2,6 +2,23 @@ * gnc-employee-xml-v2.h -- employee xml i/o parser/unparser * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_EMPLOYEE_XML_V2_H diff --git a/src/business/business-core/file/gnc-entry-xml-v2.c b/src/business/business-core/file/gnc-entry-xml-v2.c index c2cb703e15..2c06c6d11b 100644 --- a/src/business/business-core/file/gnc-entry-xml-v2.c +++ b/src/business/business-core/file/gnc-entry-xml-v2.c @@ -49,9 +49,10 @@ #include "gnc-owner-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" +#include "qofinstance.h" +#include "qofobject.h" -#define _GNC_MOD_NAME GNC_ENTRY_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_ENTRY static short module = MOD_IO; @@ -123,7 +124,7 @@ entry_dom_tree_create (GncEntry *entry) xmlSetProp(ret, "version", entry_version_string); xmlAddChild(ret, guid_to_dom_tree(entry_guid_string, - gncEntryGetGUID (entry))); + qof_instance_get_guid(QOF_INSTANCE(entry)))); ts = gncEntryGetDate (entry); xmlAddChild(ret, timespec_to_dom_tree (entry_date_string, &ts)); @@ -143,7 +144,7 @@ entry_dom_tree_create (GncEntry *entry) acc = gncEntryGetInvAccount (entry); if (acc) xmlAddChild (ret, guid_to_dom_tree (entry_invacct_string, - xaccAccountGetGUID (acc))); + qof_instance_get_guid(QOF_INSTANCE(acc)))); maybe_add_numeric (ret, entry_iprice_string, gncEntryGetInvPrice (entry)); @@ -152,7 +153,7 @@ entry_dom_tree_create (GncEntry *entry) invoice = gncEntryGetInvoice (entry); if (invoice) { xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string, - gncInvoiceGetGUID (invoice))); + qof_instance_get_guid(QOF_INSTANCE(invoice)))); xmlAddChild(ret, text_to_dom_tree(entry_idisctype_string, gncAmountTypeToString ( @@ -170,14 +171,14 @@ entry_dom_tree_create (GncEntry *entry) taxtable = gncEntryGetInvTaxTable (entry); if (taxtable) xmlAddChild (ret, guid_to_dom_tree (entry_itaxtable_string, - gncTaxTableGetGUID (taxtable))); + qof_instance_get_guid (QOF_INSTANCE(taxtable)))); /* vendor bills */ acc = gncEntryGetBillAccount (entry); if (acc) xmlAddChild (ret, guid_to_dom_tree (entry_billacct_string, - xaccAccountGetGUID (acc))); + qof_instance_get_guid (QOF_INSTANCE(acc)))); maybe_add_numeric (ret, entry_bprice_string, gncEntryGetBillPrice (entry)); @@ -185,7 +186,7 @@ entry_dom_tree_create (GncEntry *entry) if (invoice) { GncOwner *owner; xmlAddChild (ret, guid_to_dom_tree (entry_bill_string, - gncInvoiceGetGUID (invoice))); + qof_instance_get_guid(QOF_INSTANCE(invoice)))); xmlAddChild(ret, int_to_dom_tree(entry_billable_string, gncEntryGetBillable (entry))); owner = gncEntryGetBillTo (entry); @@ -203,14 +204,14 @@ entry_dom_tree_create (GncEntry *entry) taxtable = gncEntryGetBillTaxTable (entry); if (taxtable) xmlAddChild (ret, guid_to_dom_tree (entry_btaxtable_string, - gncTaxTableGetGUID (taxtable))); + qof_instance_get_guid (QOF_INSTANCE(taxtable)))); /* Other stuff */ order = gncEntryGetOrder (entry); if (order) xmlAddChild (ret, guid_to_dom_tree (entry_order_string, - gncOrderGetGUID (order))); + qof_instance_get_guid(QOF_INSTANCE (order)))); return ret; } @@ -784,7 +785,7 @@ entry_sixtp_parser_create(void) } static void -do_count (gpointer entry_p, gpointer count_p) +do_count (QofEntity * entry_p, gpointer count_p) { int *count = count_p; (*count)++; @@ -794,15 +795,15 @@ static int entry_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_entry (gpointer entry_p, gpointer out_p) +xml_add_entry (QofEntity * entry_p, gpointer out_p) { xmlNodePtr node; - GncEntry *entry = entry_p; + GncEntry *entry = (GncEntry *) entry_p; FILE *out = out_p; /* Don't save non-attached entries! */ @@ -819,7 +820,7 @@ xml_add_entry (gpointer entry_p, gpointer out_p) static void entry_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out); } void @@ -835,7 +836,7 @@ gnc_entry_xml_initialize (void) NULL, /* scrub */ }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-entry-xml-v2.h b/src/business/business-core/file/gnc-entry-xml-v2.h index d960bf96aa..c0424ce3dd 100644 --- a/src/business/business-core/file/gnc-entry-xml-v2.h +++ b/src/business/business-core/file/gnc-entry-xml-v2.h @@ -2,6 +2,23 @@ * gnc-entry-xml-v2.h -- entry xml i/o parser/unparsers * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_ENTRY_XML_V2_H diff --git a/src/business/business-core/file/gnc-invoice-xml-v2.c b/src/business/business-core/file/gnc-invoice-xml-v2.c index 26a3299a6a..9245776f71 100644 --- a/src/business/business-core/file/gnc-invoice-xml-v2.c +++ b/src/business/business-core/file/gnc-invoice-xml-v2.c @@ -47,9 +47,10 @@ #include "gnc-owner-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" +#include "qofinstance.h" +#include "qofobject.h" -#define _GNC_MOD_NAME GNC_INVOICE_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_INVOICE static short module = MOD_IO; @@ -104,7 +105,7 @@ invoice_dom_tree_create (GncInvoice *invoice) xmlSetProp(ret, "version", invoice_version_string); xmlAddChild(ret, guid_to_dom_tree(invoice_guid_string, - gncInvoiceGetGUID (invoice))); + qof_instance_get_guid(QOF_INSTANCE(invoice)))); xmlAddChild(ret, text_to_dom_tree(invoice_id_string, gncInvoiceGetID (invoice))); @@ -121,7 +122,7 @@ invoice_dom_tree_create (GncInvoice *invoice) term = gncInvoiceGetTerms (invoice); if (term) xmlAddChild(ret, guid_to_dom_tree(invoice_terms_string, - gncBillTermGetGUID (term))); + qof_instance_get_guid (QOF_INSTANCE(term)))); maybe_add_string (ret, invoice_billing_id_string, gncInvoiceGetBillingID (invoice)); @@ -143,7 +144,7 @@ invoice_dom_tree_create (GncInvoice *invoice) acc = gncInvoiceGetPostedAcc (invoice); if (acc) xmlAddChild (ret, guid_to_dom_tree (invoice_postacc_string, - xaccAccountGetGUID (acc))); + qof_instance_get_guid(QOF_INSTANCE(acc)))); xmlAddChild (ret, @@ -510,10 +511,10 @@ invoice_should_be_saved (GncInvoice *invoice) } static void -do_count (gpointer invoice_p, gpointer count_p) +do_count (QofEntity * invoice_p, gpointer count_p) { int *count = count_p; - if (invoice_should_be_saved (invoice_p)) + if (invoice_should_be_saved ((GncInvoice *)invoice_p)) (*count)++; } @@ -521,15 +522,15 @@ static int invoice_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_invoice (gpointer invoice_p, gpointer out_p) +xml_add_invoice (QofEntity * invoice_p, gpointer out_p) { xmlNodePtr node; - GncInvoice *invoice = invoice_p; + GncInvoice *invoice = (GncInvoice *) invoice_p; FILE *out = out_p; if (!invoice_should_be_saved (invoice)) @@ -544,7 +545,7 @@ xml_add_invoice (gpointer invoice_p, gpointer out_p) static void invoice_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_invoice, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_invoice, (gpointer) out); } void @@ -560,7 +561,7 @@ gnc_invoice_xml_initialize (void) NULL, /* scrub */ }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-invoice-xml-v2.h b/src/business/business-core/file/gnc-invoice-xml-v2.h index 421584c956..c08ea3ff82 100644 --- a/src/business/business-core/file/gnc-invoice-xml-v2.h +++ b/src/business/business-core/file/gnc-invoice-xml-v2.h @@ -2,6 +2,23 @@ * gnc-invoice-xml-v2.h -- invoice xml i/o parser/unparsers * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_INVOICE_XML_V2_H diff --git a/src/business/business-core/file/gnc-job-xml-v2.c b/src/business/business-core/file/gnc-job-xml-v2.c index 60cf9786ab..82091f3fa5 100644 --- a/src/business/business-core/file/gnc-job-xml-v2.c +++ b/src/business/business-core/file/gnc-job-xml-v2.c @@ -46,9 +46,10 @@ #include "gnc-owner-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" +#include "qofobject.h" +#include "xml-helpers.h" -#define _GNC_MOD_NAME GNC_JOB_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_JOB static short module = MOD_IO; @@ -64,13 +65,6 @@ const gchar *job_version_string = "2.0.0"; #define job_active_string "job:active" #define job_slots_string "job:slots" -static void -maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) -{ - if (str && strlen(str) > 0) - xmlAddChild (ptr, text_to_dom_tree (tag, str)); -} - static xmlNodePtr job_dom_tree_create (GncJob *job) { @@ -80,7 +74,7 @@ job_dom_tree_create (GncJob *job) xmlSetProp(ret, "version", job_version_string); xmlAddChild(ret, guid_to_dom_tree(job_guid_string, - gncJobGetGUID (job))); + qof_instance_get_guid (QOF_INSTANCE (job)))); xmlAddChild(ret, text_to_dom_tree(job_id_string, gncJobGetID (job))); @@ -297,10 +291,10 @@ job_should_be_saved (GncJob *job) } static void -do_count (gpointer job_p, gpointer count_p) +do_count (QofEntity * job_p, gpointer count_p) { int *count = count_p; - if (job_should_be_saved (job_p)) + if (job_should_be_saved ((GncJob *)job_p)) (*count)++; } @@ -308,15 +302,15 @@ static int job_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_job (gpointer job_p, gpointer out_p) +xml_add_job (QofEntity * job_p, gpointer out_p) { xmlNodePtr node; - GncJob *job = job_p; + GncJob *job = (GncJob *) job_p; FILE *out = out_p; if (!job_should_be_saved (job)) @@ -331,7 +325,7 @@ xml_add_job (gpointer job_p, gpointer out_p) static void job_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out); } void @@ -347,7 +341,7 @@ gnc_job_xml_initialize (void) NULL, /* scrub */ }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-job-xml-v2.h b/src/business/business-core/file/gnc-job-xml-v2.h index fc606503a5..41d2b6f9ae 100644 --- a/src/business/business-core/file/gnc-job-xml-v2.h +++ b/src/business/business-core/file/gnc-job-xml-v2.h @@ -2,6 +2,23 @@ * gnc-job-xml-v2.h -- job xml i/o parser/unparsers * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_JOB_XML_V2_H diff --git a/src/business/business-core/file/gnc-order-xml-v2.c b/src/business/business-core/file/gnc-order-xml-v2.c index e084443af7..7f389a7479 100644 --- a/src/business/business-core/file/gnc-order-xml-v2.c +++ b/src/business/business-core/file/gnc-order-xml-v2.c @@ -48,7 +48,7 @@ #include "gncObject.h" -#define _GNC_MOD_NAME GNC_ORDER_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_ORDER static short module = MOD_IO; @@ -83,7 +83,7 @@ order_dom_tree_create (GncOrder *order) xmlSetProp(ret, "version", order_version_string); xmlAddChild(ret, guid_to_dom_tree(order_guid_string, - gncOrderGetGUID (order))); + qof_instance_get_guid(QOF_INSTANCE (order)))); xmlAddChild(ret, text_to_dom_tree(order_id_string, gncOrderGetID (order))); @@ -333,10 +333,10 @@ order_should_be_saved (GncOrder *order) } static void -do_count (gpointer order_p, gpointer count_p) +do_count (QofEntity * order_p, gpointer count_p) { int *count = count_p; - if (order_should_be_saved (order_p)) + if (order_should_be_saved ((GncOrder *) order_p)) (*count)++; } @@ -349,10 +349,10 @@ order_get_count (GNCBook *book) } static void -xml_add_order (gpointer order_p, gpointer out_p) +xml_add_order (QofEntity * order_p, gpointer out_p) { xmlNodePtr node; - GncOrder *order = order_p; + GncOrder *order = (GncOrder *) order_p; FILE *out = out_p; if (!order_should_be_saved (order)) diff --git a/src/business/business-core/file/gnc-order-xml-v2.h b/src/business/business-core/file/gnc-order-xml-v2.h index ad029b0701..4786e18af1 100644 --- a/src/business/business-core/file/gnc-order-xml-v2.h +++ b/src/business/business-core/file/gnc-order-xml-v2.h @@ -2,6 +2,23 @@ * gnc-order-xml-v2.h -- order xml i/o parser/unparsers * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_ORDER_XML_V2_H diff --git a/src/business/business-core/file/gnc-owner-xml-v2.c b/src/business/business-core/file/gnc-owner-xml-v2.c index 6ceb9e70dc..702593958d 100644 --- a/src/business/business-core/file/gnc-owner-xml-v2.c +++ b/src/business/business-core/file/gnc-owner-xml-v2.c @@ -41,6 +41,8 @@ #include "io-gncxml-gen.h" #include "io-gncxml-v2.h" +#include "qofinstance.h" + #include "gnc-owner-xml-v2.h" #include "gncCustomerP.h" #include "gncJobP.h" @@ -65,16 +67,16 @@ gnc_owner_to_dom_tree (const char *tag, GncOwner *owner) switch (gncOwnerGetType (owner)) { case GNC_OWNER_CUSTOMER: - type_str = GNC_CUSTOMER_MODULE_NAME; + type_str = GNC_ID_CUSTOMER; break; case GNC_OWNER_JOB: - type_str = GNC_JOB_MODULE_NAME; + type_str = GNC_ID_JOB; break; case GNC_OWNER_VENDOR: - type_str = GNC_VENDOR_MODULE_NAME; + type_str = GNC_ID_VENDOR; break; case GNC_OWNER_EMPLOYEE: - type_str = GNC_EMPLOYEE_MODULE_NAME; + type_str = GNC_ID_EMPLOYEE; break; default: PWARN ("Invalid owner type: %d", gncOwnerGetType (owner)); @@ -86,7 +88,7 @@ gnc_owner_to_dom_tree (const char *tag, GncOwner *owner) xmlAddChild (ret, text_to_dom_tree (owner_type_string, type_str)); xmlAddChild (ret, guid_to_dom_tree (owner_id_string, - gncOwnerGetGUID (owner))); + qof_instance_get_guid (QOF_INSTANCE(owner)))); return ret; } @@ -106,13 +108,13 @@ owner_type_handler (xmlNodePtr node, gpointer owner_pdata) char* txt = dom_tree_to_text(node); g_return_val_if_fail(txt, FALSE); - if (!safe_strcmp (txt, GNC_CUSTOMER_MODULE_NAME)) + if (!safe_strcmp (txt, GNC_ID_CUSTOMER)) gncOwnerInitCustomer (pdata->owner, NULL); - else if (!safe_strcmp (txt, GNC_JOB_MODULE_NAME)) + else if (!safe_strcmp (txt, GNC_ID_JOB)) gncOwnerInitJob (pdata->owner, NULL); - else if (!safe_strcmp (txt, GNC_VENDOR_MODULE_NAME)) + else if (!safe_strcmp (txt, GNC_ID_VENDOR)) gncOwnerInitVendor (pdata->owner, NULL); - else if (!safe_strcmp (txt, GNC_EMPLOYEE_MODULE_NAME)) + else if (!safe_strcmp (txt, GNC_ID_EMPLOYEE)) gncOwnerInitEmployee (pdata->owner, NULL); else { PWARN ("Unknown owner type: %s", txt); diff --git a/src/business/business-core/file/gnc-owner-xml-v2.h b/src/business/business-core/file/gnc-owner-xml-v2.h index 10e088a9a3..bcd1537730 100644 --- a/src/business/business-core/file/gnc-owner-xml-v2.h +++ b/src/business/business-core/file/gnc-owner-xml-v2.h @@ -1,16 +1,33 @@ /* gnc-owner-xml-v2.h -- Owner XML header * * Copyright (C) 2002 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_OWNER_XML_V2_H #define GNC_OWNER_XML_V2_H #include "gncOwner.h" -#include "gnc-book.h" +#include "qofbook.h" gboolean gnc_dom_tree_to_owner (xmlNodePtr node, GncOwner *owner, - GNCBook *book); + QofBook *book); xmlNodePtr gnc_owner_to_dom_tree (const char *tag, GncOwner *addr); #endif /* GNC_OWNER_XML_V2_H */ diff --git a/src/business/business-core/file/gnc-tax-table-xml-v2.c b/src/business/business-core/file/gnc-tax-table-xml-v2.c index f5b3c8a7ba..b2b500123f 100644 --- a/src/business/business-core/file/gnc-tax-table-xml-v2.c +++ b/src/business/business-core/file/gnc-tax-table-xml-v2.c @@ -41,14 +41,15 @@ #include "io-gncxml-gen.h" #include "io-gncxml-v2.h" +#include "gncEntry.h" #include "gncTaxTableP.h" #include "gnc-tax-table-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" -#include "gncEntry.h" +#include "qofobject.h" +#include "qofinstance.h" -#define _GNC_MOD_NAME GNC_TAXTABLE_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_TAXTABLE static short module = MOD_IO; @@ -74,7 +75,8 @@ static void maybe_add_guid (xmlNodePtr ptr, const char *tag, GncTaxTable *table) { if (table) - xmlAddChild (ptr, guid_to_dom_tree (tag, gncTaxTableGetGUID (table))); + xmlAddChild (ptr, guid_to_dom_tree (tag, + qof_instance_get_guid(QOF_INSTANCE(table)))); } static xmlNodePtr @@ -89,7 +91,7 @@ ttentry_dom_tree_create (GncTaxTableEntry *entry) account = gncTaxTableEntryGetAccount (entry); if (account) xmlAddChild(ret, guid_to_dom_tree (ttentry_account_string, - xaccAccountGetGUID (account))); + qof_instance_get_guid (QOF_INSTANCE(account)))); amount = gncTaxTableEntryGetAmount (entry); xmlAddChild (ret, gnc_numeric_to_dom_tree (ttentry_amount_string, &amount)); @@ -447,7 +449,7 @@ taxtable_sixtp_parser_create(void) } static void -do_count (gpointer table_p, gpointer count_p) +do_count (QofEntity * table_p, gpointer count_p) { int *count = count_p; (*count)++; @@ -457,15 +459,15 @@ static int taxtable_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_taxtable (gpointer table_p, gpointer out_p) +xml_add_taxtable (QofEntity * table_p, gpointer out_p) { xmlNodePtr node; - GncTaxTable *table = table_p; + GncTaxTable *table = (GncTaxTable *) table_p; FILE *out = out_p; node = taxtable_dom_tree_create (table); @@ -477,7 +479,7 @@ xml_add_taxtable (gpointer table_p, gpointer out_p) static void taxtable_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_taxtable, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_taxtable, (gpointer) out); } @@ -522,9 +524,9 @@ taxtable_find_senior (GncTaxTable *table) /* build a list of tax tables that are grandchildren or bogus (empty entry list). */ static void -taxtable_scrub_cb (gpointer table_p, gpointer list_p) +taxtable_scrub_cb (QofEntity * table_p, gpointer list_p) { - GncTaxTable *table = table_p; + GncTaxTable *table = GNC_TAXTABLE(table_p); GList **list = list_p; if (taxtable_is_grandchild(table) || gncTaxTableGetEntries(table) == NULL) @@ -535,10 +537,10 @@ taxtable_scrub_cb (gpointer table_p, gpointer list_p) * grandchildren, then fix them to point to the most senior child */ static void -taxtable_scrub_entries (gpointer entry_p, gpointer ht_p) +taxtable_scrub_entries (QofEntity * entry_p, gpointer ht_p) { GHashTable *ht = ht_p; - GncEntry *entry = entry_p; + GncEntry *entry = GNC_ENTRY(entry_p); GncTaxTable *table, *new_tt; gint32 count; @@ -546,7 +548,7 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p) if (table) { if (taxtable_is_grandchild(table)) { PINFO("Fixing i-taxtable on entry %s\n", - guid_to_string(gncEntryGetGUID(entry))); + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry)))); new_tt = taxtable_find_senior(table); gncEntryBeginEdit(entry); gncEntrySetInvTaxTable(entry, new_tt); @@ -564,7 +566,7 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p) if (table) { if (taxtable_is_grandchild(table)) { PINFO("Fixing b-taxtable on entry %s\n", - guid_to_string(gncEntryGetGUID(entry))); + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry)))); new_tt = taxtable_find_senior(table); gncEntryBeginEdit(entry); gncEntrySetBillTaxTable(entry, new_tt); @@ -580,10 +582,10 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p) } static void -taxtable_scrub_cust (gpointer cust_p, gpointer ht_p) +taxtable_scrub_cust (QofEntity * cust_p, gpointer ht_p) { GHashTable *ht = ht_p; - GncCustomer *cust = cust_p; + GncCustomer *cust = GNC_CUSTOMER(cust_p); GncTaxTable *table; gint32 count; @@ -596,10 +598,10 @@ taxtable_scrub_cust (gpointer cust_p, gpointer ht_p) } static void -taxtable_scrub_vendor (gpointer vendor_p, gpointer ht_p) +taxtable_scrub_vendor (QofEntity * vendor_p, gpointer ht_p) { GHashTable *ht = ht_p; - GncVendor *vendor = vendor_p; + GncVendor *vendor = GNC_VENDOR(vendor_p); GncTaxTable *table; gint32 count; @@ -619,7 +621,7 @@ taxtable_reset_refcount (gpointer key, gpointer value, gpointer notused) if (count != gncTaxTableGetRefcount(table) && !gncTaxTableGetInvisible(table)) { PWARN("Fixing refcount on taxtable %s (%lld -> %d)\n", - guid_to_string(gncTaxTableGetGUID(table)), + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))), gncTaxTableGetRefcount(table), count) gncTaxTableSetRefcount(table, count); } @@ -633,17 +635,17 @@ taxtable_scrub (GNCBook *book) GncTaxTable *parent, *table; GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); - gncObjectForeach (GNC_ENTRY_MODULE_NAME, book, taxtable_scrub_entries, ht); - gncObjectForeach (GNC_CUSTOMER_MODULE_NAME, book, taxtable_scrub_cust, ht); - gncObjectForeach (GNC_VENDOR_MODULE_NAME, book, taxtable_scrub_vendor, ht); - gncObjectForeach (_GNC_MOD_NAME, book, taxtable_scrub_cb, &list); + qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht); + qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht); + qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht); + qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list); /* destroy the list of "grandchildren" tax tables */ for (node = list; node; node = node->next) { table = node->data; PINFO ("deleting grandchild taxtable: %s\n", - guid_to_string(gncTaxTableGetGUID(table))); + guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table)))); /* Make sure the parent has no children */ parent = gncTaxTableGetParent(table); @@ -674,7 +676,7 @@ gnc_taxtable_xml_initialize (void) taxtable_scrub, }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-tax-table-xml-v2.h b/src/business/business-core/file/gnc-tax-table-xml-v2.h index 3bd1cd0fcd..8e5c90d104 100644 --- a/src/business/business-core/file/gnc-tax-table-xml-v2.h +++ b/src/business/business-core/file/gnc-tax-table-xml-v2.h @@ -2,6 +2,23 @@ * gnc-tax-table-xml-v2.h -- tax table xml i/o parser/unparsers * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_TAXTABLE_XML_V2_H diff --git a/src/business/business-core/file/gnc-vendor-xml-v2.c b/src/business/business-core/file/gnc-vendor-xml-v2.c index 642f5f2e84..ccc9f6a179 100644 --- a/src/business/business-core/file/gnc-vendor-xml-v2.c +++ b/src/business/business-core/file/gnc-vendor-xml-v2.c @@ -48,9 +48,12 @@ #include "gnc-address-xml-v2.h" #include "gnc-engine-util.h" -#include "gncObject.h" +#include "qofinstance.h" +#include "qofobject.h" -#define _GNC_MOD_NAME GNC_VENDOR_MODULE_NAME +#include "xml-helpers.h" + +#define _GNC_MOD_NAME GNC_ID_VENDOR static short module = MOD_IO; @@ -71,13 +74,6 @@ const gchar *vendor_version_string = "2.0.0"; #define vendor_taxtableoverride_string "vendor:use-tt" #define vendor_slots_string "vendor:slots" -static void -maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str) -{ - if (str && strlen(str) > 0) - xmlAddChild (ptr, text_to_dom_tree (tag, str)); -} - static xmlNodePtr vendor_dom_tree_create (GncVendor *vendor) { @@ -89,7 +85,7 @@ vendor_dom_tree_create (GncVendor *vendor) xmlSetProp(ret, "version", vendor_version_string); xmlAddChild(ret, guid_to_dom_tree(vendor_guid_string, - gncVendorGetGUID (vendor))); + qof_instance_get_guid (QOF_INSTANCE(vendor)))); xmlAddChild(ret, text_to_dom_tree(vendor_name_string, gncVendorGetName (vendor))); @@ -105,7 +101,7 @@ vendor_dom_tree_create (GncVendor *vendor) term = gncVendorGetTerms (vendor); if (term) xmlAddChild(ret, guid_to_dom_tree(vendor_terms_string, - gncBillTermGetGUID (term))); + qof_instance_get_guid(QOF_INSTANCE(term)))); xmlAddChild(ret, text_to_dom_tree(vendor_taxincluded_string, gncTaxIncludedTypeToString ( @@ -124,7 +120,7 @@ vendor_dom_tree_create (GncVendor *vendor) taxtable = gncVendorGetTaxTable (vendor); if (taxtable) xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string, - gncTaxTableGetGUID (taxtable))); + qof_instance_get_guid(QOF_INSTANCE(taxtable)))); return ret; } @@ -422,10 +418,10 @@ vendor_should_be_saved (GncVendor *vendor) } static void -do_count (gpointer vendor_p, gpointer count_p) +do_count (QofEntity * vendor_p, gpointer count_p) { int *count = count_p; - if (vendor_should_be_saved (vendor_p)) + if (vendor_should_be_saved ((GncVendor *)vendor_p)) (*count)++; } @@ -433,15 +429,15 @@ static int vendor_get_count (GNCBook *book) { int count = 0; - gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); + qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count); return count; } static void -xml_add_vendor (gpointer vendor_p, gpointer out_p) +xml_add_vendor (QofEntity * vendor_p, gpointer out_p) { xmlNodePtr node; - GncVendor *vendor = vendor_p; + GncVendor *vendor = (GncVendor *) vendor_p; FILE *out = out_p; if (!vendor_should_be_saved (vendor)) @@ -456,7 +452,7 @@ xml_add_vendor (gpointer vendor_p, gpointer out_p) static void vendor_write (FILE *out, GNCBook *book) { - gncObjectForeach (_GNC_MOD_NAME, book, xml_add_vendor, (gpointer) out); + qof_object_foreach (_GNC_MOD_NAME, book, xml_add_vendor, (gpointer) out); } void @@ -472,7 +468,7 @@ gnc_vendor_xml_initialize (void) NULL, /* scrub */ }; - gncObjectRegisterBackend (_GNC_MOD_NAME, + qof_object_register_backend (_GNC_MOD_NAME, GNC_FILE_BACKEND, &be_data); } diff --git a/src/business/business-core/file/gnc-vendor-xml-v2.h b/src/business/business-core/file/gnc-vendor-xml-v2.h index 3fb6593945..f85830a4e2 100644 --- a/src/business/business-core/file/gnc-vendor-xml-v2.h +++ b/src/business/business-core/file/gnc-vendor-xml-v2.h @@ -2,6 +2,23 @@ * gnc-vendor-xml-v2.h -- vendor xml i/o parser/unparsers * * Copyright (C) 2000 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_VENDOR_XML_V2_H diff --git a/src/business/business-core/file/gncmod-business-backend-file.c b/src/business/business-core/file/gncmod-business-backend-file.c index c4f0cdedf0..2723fbcff7 100644 --- a/src/business/business-core/file/gncmod-business-backend-file.c +++ b/src/business/business-core/file/gncmod-business-backend-file.c @@ -3,6 +3,24 @@ * module definition/initialization for the file backend module * * Copyright (c) 2002 Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org + * *********************************************************************/ #include diff --git a/src/business/business-core/gncAddress.c b/src/business/business-core/gncAddress.c index 29284f0a92..3dc7a003a5 100644 --- a/src/business/business-core/gncAddress.c +++ b/src/business/business-core/gncAddress.c @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncAddress.c -- an Address object * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncAddress.h -- an Address object * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ @@ -10,17 +31,17 @@ #include "gnc-engine-util.h" /* safe_strcmp */ #include "qofquerycore.h" -#include "qofqueryobject.h" +#include "qofclass.h" #include "guid.h" #include "gnc-event-p.h" #include "gncAddress.h" #include "gncAddressP.h" -struct _gncAddress { +struct _gncAddress +{ QofBook * book; - const GUID * parent_guid; - QofIdType parent_type; + QofEntity * parent; gboolean dirty; char * name; char * addr1; @@ -30,7 +51,6 @@ struct _gncAddress { char * phone; char * fax; char * email; - }; #define _GNC_MOD_NAME GNC_ADDRESS_MODULE_NAME @@ -44,12 +64,13 @@ mark_address (GncAddress *address) { address->dirty = TRUE; - gnc_engine_generate_event (address->parent_guid, address->parent_type, GNC_EVENT_MODIFY); + gnc_engine_gen_event (address->parent, GNC_EVENT_MODIFY); } /* Create/Destroy functions */ -GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptype) +GncAddress * +gncAddressCreate (QofBook *book, QofEntity *prnt) { GncAddress *addr; @@ -58,8 +79,7 @@ GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptyp addr = g_new0 (GncAddress, 1); addr->book = book; addr->dirty = FALSE; - addr->parent_guid = parent; - addr->parent_type = ptype; + addr->parent = prnt; addr->name = CACHE_INSERT (""); addr->addr1 = CACHE_INSERT (""); @@ -73,7 +93,33 @@ GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptyp return addr; } -void gncAddressDestroy (GncAddress *addr){ +GncAddress * +gncCloneAddress (GncAddress *from, QofEntity *new_parent, QofBook *book) +{ + GncAddress *addr; + + if (!book) return NULL; + + addr = g_new0 (GncAddress, 1); + addr->book = book; + addr->dirty = TRUE; + addr->parent = new_parent; + + addr->name = CACHE_INSERT (from->name); + addr->addr1 = CACHE_INSERT (from->addr1); + addr->addr2 = CACHE_INSERT (from->addr2); + addr->addr3 = CACHE_INSERT (from->addr3); + addr->addr4 = CACHE_INSERT (from->addr4); + addr->phone = CACHE_INSERT (from->phone); + addr->fax = CACHE_INSERT (from->fax); + addr->email = CACHE_INSERT (from->email); + + return addr; +} + +void +gncAddressDestroy (GncAddress *addr) +{ if (!addr) return; CACHE_REMOVE (addr->name); @@ -93,6 +139,7 @@ void gncAddressDestroy (GncAddress *addr){ #define SET_STR(member, str) { \ char * tmp; \ \ + if (member == str) return; \ if (!safe_strcmp (member, str)) return; \ tmp = CACHE_INSERT (str); \ CACHE_REMOVE (member); \ @@ -236,16 +283,16 @@ int gncAddressCompare (const GncAddress *a, const GncAddress *b) gboolean gncAddressRegister (void) { - static QofQueryObject params[] = { + static QofParam params[] = { - { ADDRESS_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetName }, - { ADDRESS_PHONE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetPhone }, - { ADDRESS_FAX, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetFax }, - { ADDRESS_EMAIL, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetEmail }, + { ADDRESS_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetName, NULL }, + { ADDRESS_PHONE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetPhone, NULL }, + { ADDRESS_FAX, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetFax, NULL }, + { ADDRESS_EMAIL, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetEmail, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncAddressCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncAddressCompare, params); return TRUE; } diff --git a/src/business/business-core/gncAddress.h b/src/business/business-core/gncAddress.h index f5ce68c924..856963ae63 100644 --- a/src/business/business-core/gncAddress.h +++ b/src/business/business-core/gncAddress.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncAddress.h -- an Address object * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncAddress.h -- an Address object * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ @@ -8,15 +29,14 @@ #define GNC_ADDRESS_H_ #include "qofbook.h" +#include "qofid.h" -#define GNC_ADDRESS_MODULE_NAME "gncAddress" +#define GNC_ADDRESS_MODULE_NAME "gncAddress" -struct _gncAddress; typedef struct _gncAddress GncAddress; /* Create/Destroy functions */ - -GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptype); +GncAddress * gncAddressCreate (QofBook *book, QofEntity *parent); void gncAddressDestroy (GncAddress *addr); /* Set functions */ @@ -45,9 +65,9 @@ gboolean gncAddressIsDirty (const GncAddress *addr); int gncAddressCompare (const GncAddress *a, const GncAddress *b); -#define ADDRESS_NAME "name" -#define ADDRESS_PHONE "phone" -#define ADDRESS_FAX "fax" -#define ADDRESS_EMAIL "email" +#define ADDRESS_NAME "name" +#define ADDRESS_PHONE "phone" +#define ADDRESS_FAX "fax" +#define ADDRESS_EMAIL "email" #endif /* GNC_ADDRESS_H_ */ diff --git a/src/business/business-core/gncAddressP.h b/src/business/business-core/gncAddressP.h index e47bb05b51..b21f0bfb32 100644 --- a/src/business/business-core/gncAddressP.h +++ b/src/business/business-core/gncAddressP.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncAddressP.h -- Private Business Interface: Addresses * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncAddressP.h -- Business Interface: Addresses * Copyright (C) 2001, 2002 Derek Atkins * Author: Derek Atkins */ @@ -7,6 +28,13 @@ #ifndef GNC_ADDRESSP_H_ #define GNC_ADDRESSP_H_ +#include "gncAddress.h" +#include "qofid.h" + gboolean gncAddressRegister (void); +/** Make a copy of the address, setting the parent to 'new_parent' */ +GncAddress * gncCloneAddress (GncAddress *from, QofEntity *new_parent, QofBook *book); + + #endif /* GNC_ADDRESSP_H_ */ diff --git a/src/business/business-core/gncBillTerm.c b/src/business/business-core/gncBillTerm.c index 604ece6573..30ec24acc9 100644 --- a/src/business/business-core/gncBillTerm.c +++ b/src/business/business-core/gncBillTerm.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncBillTerm.c -- the Gnucash Billing Terms interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncBillTerm.c -- the Gnucash Billing Terms interface * Copyright (C) 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -15,79 +37,117 @@ #include "qofquerycore.h" #include "gnc-event-p.h" #include "gnc-be-utils.h" +#include "kvp_frame.h" + #include "qofbook.h" +#include "qofclass.h" #include "qofid.h" #include "qofid-p.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" #include "qofquery.h" -#include "qofqueryobject.h" #include "gncBusiness.h" #include "gncBillTermP.h" -struct _gncBillTerm { - GUID guid; - char * name; - char * desc; - GncBillTermType type; - gint due_days; - gint disc_days; - gnc_numeric discount; - gint cutoff; +struct _gncBillTerm +{ + QofInstance inst; - gint64 refcount; - QofBook * book; - GncBillTerm * parent; /* if non-null, we are an immutable child */ - GncBillTerm * child; /* if non-null, we have not changed */ - gboolean invisible; + /* 'visible' data fields directly manipulated by user */ + char * name; + char * desc; + GncBillTermType type; + gint due_days; + gint disc_days; + gnc_numeric discount; + gint cutoff; - GList * children; /* list of children for disconnection */ - - int editlevel; - gboolean do_free; - - gboolean dirty; + /* Internal management fields */ + /* See src/doc/business.txt for an explanation of the following */ + /* Code that handles this is *identical* to that in gncTaxTable */ + gint64 refcount; + GncBillTerm * parent; /* if non-null, we are an immutable child */ + GncBillTerm * child; /* if non-null, we have not changed */ + gboolean invisible; + GList * children; /* list of children for disconnection */ }; -struct _book_info { - GncBookInfo bi; - GList * terms; /* visible terms */ +struct _book_info +{ + GList * terms; /* visible terms */ }; -static short module = MOD_BUSINESS; +static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_BILLTERM_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_BILLTERM #define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); #define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); #define SET_STR(obj, member, str) { \ - char * tmp; \ - \ - if (!safe_strcmp (member, str)) return; \ - gncBillTermBeginEdit (obj); \ - tmp = CACHE_INSERT (str); \ - CACHE_REMOVE (member); \ - member = tmp; \ - } + char * tmp; \ + \ + if (!safe_strcmp (member, str)) return; \ + gncBillTermBeginEdit (obj); \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } -static void add_or_rem_object (GncBillTerm *term, gboolean add); -static void addObj (GncBillTerm *term); -static void remObj (GncBillTerm *term); -static void maybe_resort_list (GncBillTerm *term); +/* ============================================================== */ +/* Misc inline utilities */ -static void gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child); - -G_INLINE_FUNC void mark_term (GncBillTerm *term); -G_INLINE_FUNC void +static inline void mark_term (GncBillTerm *term) { - term->dirty = TRUE; - gncBusinessSetDirtyFlag (term->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&term->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + term->inst.dirty = TRUE; + qof_collection_mark_dirty (term->inst.entity.collection); + gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_MODIFY); } +static inline void maybe_resort_list (GncBillTerm *term) +{ + struct _book_info *bi; + + if (term->parent || term->invisible) return; + bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME); + bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare); +} + +static inline void addObj (GncBillTerm *term) +{ + struct _book_info *bi; + bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME); + bi->terms = g_list_insert_sorted (bi->terms, term, + (GCompareFunc)gncBillTermCompare); +} + +static inline void remObj (GncBillTerm *term) +{ + struct _book_info *bi; + bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME); + bi->terms = g_list_remove (bi->terms, term); +} + +static inline void +gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child) +{ + g_return_if_fail(table->inst.do_free == FALSE); + table->children = g_list_prepend(table->children, child); +} + +static inline void +gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child) +{ + if (table->inst.do_free) return; + table->children = g_list_remove(table->children, child); +} + +/* ============================================================== */ + /* Create/Destroy Functions */ GncBillTerm * gncBillTermCreate (QofBook *book) { @@ -95,21 +155,20 @@ GncBillTerm * gncBillTermCreate (QofBook *book) if (!book) return NULL; term = g_new0 (GncBillTerm, 1); - term->book = book; + qof_instance_init(&term->inst, _GNC_MOD_NAME, book); term->name = CACHE_INSERT (""); term->desc = CACHE_INSERT (""); term->discount = gnc_numeric_zero (); - qof_entity_guid_new (qof_book_get_entity_table (book), &term->guid); addObj (term); - gnc_engine_generate_event (&term->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_CREATE); return term; } void gncBillTermDestroy (GncBillTerm *term) { if (!term) return; - term->do_free = TRUE; - gncBusinessSetDirtyFlag (term->book, _GNC_MOD_NAME, TRUE); + term->inst.do_free = TRUE; + qof_collection_mark_dirty (term->inst.entity.collection); gncBillTermCommitEdit (term); } @@ -120,12 +179,12 @@ static void gncBillTermFree (GncBillTerm *term) if (!term) return; - gnc_engine_generate_event (&term->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (term->name); CACHE_REMOVE (term->desc); remObj (term); - if (!term->do_free) + if (!term->inst.do_free) PERR("free a billterm without do_free set!"); /* disconnect from parent */ @@ -139,44 +198,75 @@ static void gncBillTermFree (GncBillTerm *term) } g_list_free(term->children); + qof_instance_release(&term->inst); g_free (term); } -static void -gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child) +GncBillTerm * +gncCloneBillTerm (GncBillTerm *from, QofBook *book) { - g_return_if_fail(table); - g_return_if_fail(child); - g_return_if_fail(table->do_free == FALSE); + GList *node; + GncBillTerm *term; - table->children = g_list_prepend(table->children, child); -} + if (!book || !from) return NULL; -static void -gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child) -{ - g_return_if_fail(table); - g_return_if_fail(child); + term = g_new0 (GncBillTerm, 1); + qof_instance_init(&term->inst, _GNC_MOD_NAME, book); + qof_instance_gemini (&term->inst, &from->inst); - if (table->do_free) - return; + term->name = CACHE_INSERT (from->name); + term->desc = CACHE_INSERT (from->desc); + term->type = from->type; + term->due_days = from->due_days; + term->disc_days = from->disc_days; + term->discount = from->discount; + term->cutoff = from->cutoff; + term->invisible = from->invisible; - table->children = g_list_remove(table->children, child); -} + term->refcount = 0; -/* Set Functions */ -void gncBillTermSetGUID (GncBillTerm *term, const GUID *guid) -{ - if (!term || !guid) return; - if (guid_equal (guid, &term->guid)) return; + /* Make copies of parents and children. Note that this can be + * a recursive copy ... treat as doubly-linked list. */ + if (from->child) + { + term->child = gncBillTermObtainTwin (from->child, book); + term->child->parent = term; + } + if (from->parent) + { + term->parent = gncBillTermObtainTwin (from->parent, book); + term->parent->child = term; + } + for (node=g_list_last(from->children); node; node=node->next) + { + GncBillTerm *btrm = node->data; + btrm = gncBillTermObtainTwin (btrm, book); + btrm->parent = term; + term->children = g_list_prepend(term->children, btrm); + } - gncBillTermBeginEdit (term); - remObj (term); - term->guid = *guid; addObj (term); - gncBillTermCommitEdit (term); + gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_CREATE); + return term; } +GncBillTerm * +gncBillTermObtainTwin (GncBillTerm *from, QofBook *book) +{ + GncBillTerm *term; + if (!from) return NULL; + + term = (GncBillTerm *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!term) + { + term = gncCloneBillTerm (from, book); + } + return term; +} + +/* ============================================================== */ +/* Set Functions */ + void gncBillTermSetName (GncBillTerm *term, const char *name) { if (!term || !name) return; @@ -245,6 +335,11 @@ void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff) gncBillTermCommitEdit (term); } +/* XXX this doesn't seem right. If the parent/child relationship + * is a doubly-linked list, then there shouldn't be separate set-parent, + * set-child routines, else misuse of the routines will goof up + * relationships. These ops should be atomic, I think. + */ void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent) { if (!term) return; @@ -270,7 +365,7 @@ void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child) void gncBillTermIncRef (GncBillTerm *term) { if (!term) return; - if (term->parent || term->invisible) return; /* children dont need refcounts */ + if (term->parent || term->invisible) return; /* children dont need refcounts */ gncBillTermBeginEdit (term); term->refcount++; gncBillTermCommitEdit (term); @@ -279,7 +374,7 @@ void gncBillTermIncRef (GncBillTerm *term) void gncBillTermDecRef (GncBillTerm *term) { if (!term) return; - if (term->parent || term->invisible) return; /* children dont need refcounts */ + if (term->parent || term->invisible) return; /* children dont need refcounts */ gncBillTermBeginEdit (term); term->refcount--; g_return_if_fail (term->refcount >= 0); @@ -297,7 +392,7 @@ void gncBillTermMakeInvisible (GncBillTerm *term) if (!term) return; gncBillTermBeginEdit (term); term->invisible = TRUE; - add_or_rem_object (term, FALSE); + remObj (term); gncBillTermCommitEdit (term); } @@ -309,33 +404,30 @@ void gncBillTermChanged (GncBillTerm *term) void gncBillTermBeginEdit (GncBillTerm *term) { - GNC_BEGIN_EDIT (term, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&term->inst); } -static void gncBillTermOnError (GncBillTerm *term, QofBackendError errcode) +static void gncBillTermOnError (QofInstance *inst, QofBackendError errcode) { PERR("BillTerm QofBackend Failure: %d", errcode); } -static void gncBillTermOnDone (GncBillTerm *term) +static inline void bill_free (QofInstance *inst) { - term->dirty = FALSE; + GncBillTerm *term = (GncBillTerm *) inst; + gncBillTermFree(term); } +static inline void on_done (QofInstance *inst) {} + void gncBillTermCommitEdit (GncBillTerm *term) { - GNC_COMMIT_EDIT_PART1 (term); - GNC_COMMIT_EDIT_PART2 (term, _GNC_MOD_NAME, gncBillTermOnError, - gncBillTermOnDone, gncBillTermFree); + GNC_COMMIT_EDIT_PART1 (&term->inst); + GNC_COMMIT_EDIT_PART2 (&term->inst, gncBillTermOnError, + on_done, bill_free); } /* Get Functions */ -GncBillTerm * gncBillTermLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name) { @@ -354,23 +446,10 @@ GList * gncBillTermGetTerms (QofBook *book) struct _book_info *bi; if (!book) return NULL; - bi = gnc_book_get_data (book, _GNC_MOD_NAME); + bi = qof_book_get_data (book, _GNC_MOD_NAME); return bi->terms; } - -const GUID *gncBillTermGetGUID (GncBillTerm *term) -{ - if (!term) return NULL; - return &term->guid; -} - -QofBook *gncBillTermGetBook (GncBillTerm *term) -{ - if (!term) return NULL; - return term->book; -} - const char *gncBillTermGetName (GncBillTerm *term) { if (!term) return NULL; @@ -418,7 +497,7 @@ static GncBillTerm *gncBillTermCopy (GncBillTerm *term) GncBillTerm *t; if (!term) return NULL; - t = gncBillTermCreate (term->book); + t = gncBillTermCreate (term->inst.book); gncBillTermBeginEdit(t); @@ -486,7 +565,7 @@ int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b) gboolean gncBillTermIsDirty (GncBillTerm *term) { if (!term) return FALSE; - return term->dirty; + return term->inst.dirty; } /********************************************************/ @@ -496,10 +575,11 @@ gboolean gncBillTermIsDirty (GncBillTerm *term) /* Based on the timespec and a proximo type, compute the month and * year this is due. The actual day is filled in below. + * XXX explain this, the logic is totally opaque to me. */ static void compute_monthyear (GncBillTerm *term, Timespec post_date, - int *month, int *year) + int *month, int *year) { int iday, imonth, iyear; int cutoff = term->cutoff; @@ -528,6 +608,8 @@ compute_monthyear (GncBillTerm *term, Timespec post_date, if (year) *year = iyear; } +/* XXX explain this, the logic is totally opaque to me. */ + static Timespec compute_time (GncBillTerm *term, Timespec post_date, int days) { @@ -569,41 +651,6 @@ gncBillTermComputeDiscountDate (GncBillTerm *term, Timespec post_date) /* Package-Private functions */ -static void maybe_resort_list (GncBillTerm *term) -{ - struct _book_info *bi; - - if (term->parent || term->invisible) return; - bi = gnc_book_get_data (term->book, _GNC_MOD_NAME); - bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare); -} - -static void add_or_rem_object (GncBillTerm *term, gboolean add) -{ - struct _book_info *bi; - - if (!term) return; - bi = gnc_book_get_data (term->book, _GNC_MOD_NAME); - - if (add) - bi->terms = g_list_insert_sorted (bi->terms, term, - (GCompareFunc)gncBillTermCompare); - else - bi->terms = g_list_remove (bi->terms, term); -} - -static void addObj (GncBillTerm *term) -{ - gncBusinessAddObject (term->book, _GNC_MOD_NAME, term, &term->guid); - add_or_rem_object (term, TRUE); -} - -static void remObj (GncBillTerm *term) -{ - gncBusinessRemoveObject (term->book, _GNC_MOD_NAME, &term->guid); - add_or_rem_object (term, FALSE); -} - static void _gncBillTermCreate (QofBook *book) { struct _book_info *bi; @@ -611,8 +658,7 @@ static void _gncBillTermCreate (QofBook *book) if (!book) return; bi = g_new0 (struct _book_info, 1); - bi->bi.ht = guid_hash_table_new (); - gnc_book_set_data (book, _GNC_MOD_NAME, bi); + qof_book_set_data (book, _GNC_MOD_NAME, bi); } static void _gncBillTermDestroy (QofBook *book) @@ -621,51 +667,34 @@ static void _gncBillTermDestroy (QofBook *book) if (!book) return; - bi = gnc_book_get_data (book, _GNC_MOD_NAME); + bi = qof_book_get_data (book, _GNC_MOD_NAME); - /* XXX : Destroy the objects? */ - g_hash_table_destroy (bi->bi.ht); g_list_free (bi->terms); g_free (bi); } -static gboolean _gncBillTermIsDirty (QofBook *book) +static QofObject gncBillTermDesc = { - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncBillTermMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncBillTermForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - -static QofObject gncBillTermDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Billing Term", - _gncBillTermCreate, - _gncBillTermDestroy, - _gncBillTermIsDirty, - _gncBillTermMarkClean, - _gncBillTermForeach, - NULL /* printable */ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Billing Term", + book_begin: _gncBillTermCreate, + book_end: _gncBillTermDestroy, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: NULL }; gboolean gncBillTermRegister (void) { - static QofQueryObject params[] = { - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncBillTermGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncBillTermGetGUID }, + static QofParam params[] = { + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params); return qof_object_register (&gncBillTermDesc); } diff --git a/src/business/business-core/gncBillTerm.h b/src/business/business-core/gncBillTerm.h index d12a6942d6..6448445ca4 100644 --- a/src/business/business-core/gncBillTerm.h +++ b/src/business/business-core/gncBillTerm.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncBillTerm.h -- the Gnucash Billing Term interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncBillTerm.h -- the Gnucash Billing Term interface * Copyright (C) 2002 Derek Atkins * Author: Derek Atkins */ @@ -9,15 +30,21 @@ typedef struct _gncBillTerm GncBillTerm; -#include "gnc-numeric.h" -#include "gnc-book.h" #include "gnc-date.h" +#include "gnc-numeric.h" +#include "qofbook.h" +#include "qofid.h" +#include "qofinstance.h" +#include "gncBusiness.h" -#define GNC_BILLTERM_MODULE_NAME "gncBillTerm" +#define GNC_ID_BILLTERM "gncBillTerm" +#define GNC_IS_BILLTERM(obj) (QOF_CHECK_TYPE((obj), GNC_ID_BILLTERM)) +#define GNC_BILLTERM(obj) (QOF_CHECK_CAST((obj), GNC_ID_BILLTERM, GncBillTerm)) /* - * How to interpret the amount. + * How to interpret the amount. * You can interpret it as a VALUE or a PERCENT. + * ??? huh? */ typedef enum { GNC_TERM_TYPE_DAYS = 1, @@ -45,12 +72,20 @@ void gncBillTermBeginEdit (GncBillTerm *term); void gncBillTermCommitEdit (GncBillTerm *term); /* Get Functions */ -GncBillTerm *gncBillTermLookup (QofBook *book, const GUID *guid); + +/** Return a pointer to the instance gncBillTerm that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncBillTerm * gncBillTermLookup (QofBook *book, const GUID *guid); + */ +#define gncBillTermLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_BILLTERM, GncBillTerm) + GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name); GList * gncBillTermGetTerms (QofBook *book); +KvpFrame* gncBillTermGetSlots (GncBillTerm *term); -const GUID *gncBillTermGetGUID (GncBillTerm *term); -QofBook *gncBillTermGetBook (GncBillTerm *term); const char *gncBillTermGetName (GncBillTerm *term); const char *gncBillTermGetDescription (GncBillTerm *term); GncBillTermType gncBillTermGetType (GncBillTerm *term); @@ -75,4 +110,7 @@ int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b); Timespec gncBillTermComputeDueDate (GncBillTerm *term, Timespec post_date); Timespec gncBillTermComputeDiscountDate (GncBillTerm *term, Timespec post_date); +/* deprecated */ +#define gncBillTermGetGUID(x) qof_instance_get_guid (QOF_INSTANCE(x)) + #endif /* GNC_BILLTERM_H_ */ diff --git a/src/business/business-core/gncBillTermP.h b/src/business/business-core/gncBillTermP.h index d5e383edc3..8125fa6d2c 100644 --- a/src/business/business-core/gncBillTermP.h +++ b/src/business/business-core/gncBillTermP.h @@ -1,17 +1,39 @@ +/********************************************************************\ + * gncBillTermP.h -- the Gnucash Billing Term private interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncBillTermP.h -- the Gnucash Billing Term interface: private interface * Copyright (C) 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ #ifndef GNC_BILLTERMP_H_ #define GNC_BILLTERMP_H_ +#include "qofid-p.h" #include "gncBillTerm.h" gboolean gncBillTermRegister (void); -void gncBillTermSetGUID (GncBillTerm *term, const GUID *guid); void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent); void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child); void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount); @@ -19,4 +41,31 @@ void gncBillTermMakeInvisible (GncBillTerm *term); gboolean gncBillTermGetInvisible (GncBillTerm *term); +/** The gncCloneBillTerm() routine makes a copy of the indicated + * bill term, placing it in the indicated book. It copies + * the name, description, type, due-days, discount, etc. + * It also copies (as needed) both parents and children, so that + * the parent-child relationship is correctly mirrored in the + * clone. + * XXX the refcount is mis-handled. This needs fixin.... + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ + +GncBillTerm * gncCloneBillTerm (GncBillTerm *from, QofBook *); + +/** The gncBillTermObtainTwin() will find the 'twin' of the + * indicated bill term in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneBillTerm()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncBillTerm * gncBillTermObtainTwin (GncBillTerm *from, QofBook *book); + +#define gncBillTermSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G)) + + #endif /* GNC_BILLTERMP_H_ */ diff --git a/src/business/business-core/gncBusGuile.c b/src/business/business-core/gncBusGuile.c index 1774696b6b..26ff1b7f60 100644 --- a/src/business/business-core/gncBusGuile.c +++ b/src/business/business-core/gncBusGuile.c @@ -2,6 +2,23 @@ * gncBusGuile.c -- Business Guile Helper Functions * Copyright (C) 2003 Derek Atkins * Author: Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #include "config.h" diff --git a/src/business/business-core/gncBusGuile.h b/src/business/business-core/gncBusGuile.h index 39273b578c..14c588ccb2 100644 --- a/src/business/business-core/gncBusGuile.h +++ b/src/business/business-core/gncBusGuile.h @@ -2,6 +2,23 @@ * gncBusGuile.h -- Business Guile Helper Functions * Copyright (C) 2003 Derek Atkins * Author: Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_BUSINESS_GUILE_H_ diff --git a/src/business/business-core/gncBusiness.c b/src/business/business-core/gncBusiness.c index f5a82c8c94..370d0bf120 100644 --- a/src/business/business-core/gncBusiness.c +++ b/src/business/business-core/gncBusiness.c @@ -2,6 +2,23 @@ * gncBusiness.c -- Business helper functions * Copyright (C) 2002 Derek Atkins * Author: Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #include "config.h" @@ -9,98 +26,9 @@ #include #include "gncBusiness.h" -#include "gnc-book.h" -#include "qofid.h" -#include "qofid-p.h" +#include "gncBusinessP.h" -struct _iterate { - QofEntityForeachCB cb; - gpointer user_data; -}; - -static void get_list (gpointer key, gpointer item, gpointer arg) -{ - struct _iterate *iter = arg; - iter->cb (item, iter->user_data); -} - -void gncBusinessForeach (QofBook *book, QofIdType mod_name, - QofEntityForeachCB cb, gpointer user_data) -{ - GncBookInfo *bi; - struct _iterate iter; - - if (!book || !cb) return; - - iter.cb = cb; - iter.user_data = user_data; - - bi = gnc_book_get_data (book, mod_name); - if (bi && bi->ht) - g_hash_table_foreach (bi->ht, get_list, &iter); -} - -void gncBusinessCreate (QofBook *book, QofIdType mod_name) -{ - GncBookInfo *bi; - - if (!book) return; - - bi = g_new0 (GncBookInfo, 1); - bi->ht = guid_hash_table_new (); - gnc_book_set_data (book, mod_name, bi); -} - -void gncBusinessDestroy (QofBook *book, QofIdType mod_name) -{ - GncBookInfo *bi; - - if (!book) return; - - bi = gnc_book_get_data (book, mod_name); - - /* XXX : Destroy the objects? */ - g_hash_table_destroy (bi->ht); - g_free (bi); -} - -gboolean gncBusinessIsDirty (QofBook *book, QofIdType mod_name) -{ - GncBookInfo *bi; - - if (!book) return FALSE; - - bi = gnc_book_get_data (book, mod_name); - return bi->is_dirty; -} - -void gncBusinessSetDirtyFlag (QofBook *book, QofIdType mod_name, - gboolean is_dirty) -{ - GncBookInfo *bi; - - if (!book) return; - - bi = gnc_book_get_data (book, mod_name); - bi->is_dirty = is_dirty; -} - -void gncBusinessAddObject (QofBook *book, QofIdType mod_name, - gpointer obj, const GUID *guid) -{ - GncBookInfo *bi; - - qof_entity_store (gnc_book_get_entity_table (book), obj, guid, mod_name); - bi = gnc_book_get_data (book, mod_name); - g_hash_table_insert (bi->ht, (gpointer)guid, obj); -} - -void gncBusinessRemoveObject (QofBook *book, QofIdType mod_name, - const GUID *guid) -{ - GncBookInfo *bi; - - qof_entity_remove (gnc_book_get_entity_table (book), guid); - bi = gnc_book_get_data (book, mod_name); - g_hash_table_remove (bi->ht, guid); -} +/* This file is currently unused; + * its contents have been moved to qofid.[ch] + */ +// void gncBusinessInitialize (int argc, char **argv) {} diff --git a/src/business/business-core/gncBusiness.h b/src/business/business-core/gncBusiness.h index d96c9097e0..90640e7d9d 100644 --- a/src/business/business-core/gncBusiness.h +++ b/src/business/business-core/gncBusiness.h @@ -2,32 +2,41 @@ * gncBusiness.h -- Business Helper Functions * Copyright (C) 2002 Derek Atkins * Author: Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org + * + * Currently mostly not used ... */ #ifndef GNC_BUSINESS_H_ #define GNC_BUSINESS_H_ -#include "gnc-book.h" -#include "qofobject.h" -#include "qofid.h" - -typedef struct _gncBookInfo { - GHashTable * ht; - gboolean is_dirty; -} GncBookInfo; - -void gncBusinessForeach (QofBook *book, QofIdType mod_name, - QofEntityForeachCB cb, gpointer user_data); - -void gncBusinessCreate (QofBook *book, QofIdType mod_name); -void gncBusinessDestroy (QofBook *book, QofIdType mod_name); -gboolean gncBusinessIsDirty (QofBook *book, QofIdType mod_name); -void gncBusinessSetDirtyFlag (QofBook *book, QofIdType mod_name, - gboolean is_dirty); -void gncBusinessAddObject (QofBook *book, QofIdType mod_name, - gpointer obj, const GUID *guid); -void gncBusinessRemoveObject (QofBook *book, QofIdType mod_name, - const GUID *guid); +/* deprecated backwards-compat definitions */ +#define GNC_BILLTERM_MODULE_NAME GNC_ID_BILLTERM +#define GNC_CUSTOMER_MODULE_NAME GNC_ID_CUSTOMER +#define GNC_EMPLOYEE_MODULE_NAME GNC_ID_EMPLOYEE +#define GNC_ENTRY_MODULE_NAME GNC_ID_ENTRY +#define GNC_INVOICE_MODULE_NAME GNC_ID_INVOICE +#define GNC_JOB_MODULE_NAME GNC_ID_JOB +#define GNC_ORDER_MODULE_NAME GNC_ID_ORDER +#define GNC_OWNER_MODULE_NAME GNC_ID_OWNER +#define GNC_TAXTABLE_MODULE_NAME GNC_ID_TAXTABLE +#define GNC_VENDOR_MODULE_NAME GNC_ID_VENDOR #endif /* GNC_BUSINESS_H_ */ diff --git a/src/business/business-core/gncBusinessP.h b/src/business/business-core/gncBusinessP.h index c92c933642..2c1a5a6dea 100644 --- a/src/business/business-core/gncBusinessP.h +++ b/src/business/business-core/gncBusinessP.h @@ -2,6 +2,23 @@ * gncBusinessP.h -- the Core Business Interface * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, contact: + * + * Free Software Foundation Voice: +1-617-542-5942 + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 + * Boston, MA 02111-1307, USA gnu@gnu.org */ #ifndef GNC_BUSINESSP_H_ diff --git a/src/business/business-core/gncCustomer.c b/src/business/business-core/gncCustomer.c index f8472b98bb..fe782f8762 100644 --- a/src/business/business-core/gncCustomer.c +++ b/src/business/business-core/gncCustomer.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncCustomer.c -- the Core Customer Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncCustomer.c -- the Core Customer Interface * Copyright (C) 2001,2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -13,66 +35,70 @@ #include "gnc-engine-util.h" #include "gnc-commodity.h" #include "gnc-numeric.h" -#include "qofobject.h" #include "gnc-event-p.h" #include "gnc-be-utils.h" #include "qofbook.h" +#include "qofclass.h" #include "qofid-p.h" #include "qofid.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" #include "qofquerycore.h" #include "qofquery.h" -#include "qofqueryobject.h" +#include "gncAddressP.h" +#include "gncBillTermP.h" #include "gncBusiness.h" #include "gncCustomer.h" #include "gncCustomerP.h" -#include "gncAddress.h" +#include "gncJobP.h" +#include "gncTaxTableP.h" -struct _gncCustomer { - QofBook * book; - GUID guid; - char * id; - char * name; - char * notes; - GncBillTerm * terms; - GncAddress * addr; - GncAddress * shipaddr; - gnc_commodity * currency; - gnc_numeric discount; - gnc_numeric credit; - GncTaxIncluded taxincluded; - gboolean active; - GList * jobs; +struct _gncCustomer +{ + QofInstance inst; - int editlevel; - gboolean do_free; + /* The following fields are identical to 'vendor' */ + char * id; + char * name; + char * notes; + GncBillTerm * terms; + GncAddress * addr; + gnc_commodity * currency; + GncTaxTable* taxtable; + gboolean taxtable_override; + GncTaxIncluded taxincluded; + gboolean active; + GList * jobs; - GncTaxTable* taxtable; - gboolean taxtable_override; - gboolean dirty; + /* The following fields aer unique to 'customer' */ + gnc_numeric credit; + gnc_numeric discount; + GncAddress * shipaddr; }; -static short module = MOD_BUSINESS; +static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_CUSTOMER_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_CUSTOMER + +/* ============================================================== */ +/* misc inline funcs */ #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 addObj (GncCustomer *cust); -static void remObj (GncCustomer *cust); - G_INLINE_FUNC void mark_customer (GncCustomer *customer); G_INLINE_FUNC void mark_customer (GncCustomer *customer) { - customer->dirty = TRUE; - gncBusinessSetDirtyFlag (customer->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&customer->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + customer->inst.dirty = TRUE; + qof_collection_mark_dirty (customer->inst.entity.collection); + gnc_engine_gen_event (&customer->inst.entity, GNC_EVENT_MODIFY); } +/* ============================================================== */ /* Create/Destroy Functions */ GncCustomer *gncCustomerCreate (QofBook *book) @@ -82,23 +108,65 @@ GncCustomer *gncCustomerCreate (QofBook *book) if (!book) return NULL; cust = g_new0 (GncCustomer, 1); - cust->book = book; - cust->dirty = FALSE; + qof_instance_init (&cust->inst, _GNC_MOD_NAME, book); + cust->id = CACHE_INSERT (""); cust->name = CACHE_INSERT (""); cust->notes = CACHE_INSERT (""); - cust->addr = gncAddressCreate (book, &cust->guid, _GNC_MOD_NAME); - cust->shipaddr = gncAddressCreate (book, &cust->guid, _GNC_MOD_NAME); - cust->discount = gnc_numeric_zero(); - cust->credit = gnc_numeric_zero(); + cust->addr = gncAddressCreate (book, &cust->inst.entity); cust->taxincluded = GNC_TAXINCLUDED_USEGLOBAL; cust->active = TRUE; cust->jobs = NULL; - qof_entity_guid_new (qof_book_get_entity_table (book),&cust->guid); - addObj (cust); + cust->discount = gnc_numeric_zero(); + cust->credit = gnc_numeric_zero(); + cust->shipaddr = gncAddressCreate (book, &cust->inst.entity); - gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_CREATE); + + return cust; +} + +/** Create a copy of a customer, placing the copy into a new book. */ +GncCustomer * +gncCloneCustomer (GncCustomer *from, QofBook *book) +{ + GList *node; + GncCustomer *cust; + + cust = g_new0 (GncCustomer, 1); + + qof_instance_init (&cust->inst, _GNC_MOD_NAME, book); + qof_instance_gemini (&cust->inst, &from->inst); + + cust->id = CACHE_INSERT (from->id); + cust->name = CACHE_INSERT (from->name); + cust->notes = CACHE_INSERT (from->notes); + cust->discount = from->discount; + cust->credit = from->credit; + cust->taxincluded = from->taxincluded; + cust->active = from->active; + cust->taxtable_override = from->taxtable_override; + + cust->addr = gncCloneAddress (from->addr, &cust->inst.entity, book); + cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst.entity, book); + + /* Find the matching currency in the new book, assumes + * currency has already been copied into new book. */ + cust->currency = gnc_commodity_obtain_twin (from->currency, book); + + /* Find the matching bill term, tax table in the new book */ + cust->terms = gncBillTermObtainTwin(from->terms, book); + cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book); + + for (node=g_list_last(cust->jobs); node; node=node->next) + { + GncJob *job = node->data; + job = gncJobObtainTwin (job, book); + cust->jobs = g_list_prepend(cust->jobs, job); + } + + gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_CREATE); return cust; } @@ -106,7 +174,8 @@ GncCustomer *gncCustomerCreate (QofBook *book) void gncCustomerDestroy (GncCustomer *cust) { if (!cust) return; - cust->do_free = TRUE; + cust->inst.do_free = TRUE; + qof_collection_mark_dirty (cust->inst.entity.collection); gncCustomerCommitEdit (cust); } @@ -114,7 +183,7 @@ static void gncCustomerFree (GncCustomer *cust) { if (!cust) return; - gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (cust->id); CACHE_REMOVE (cust->name); @@ -123,27 +192,41 @@ static void gncCustomerFree (GncCustomer *cust) gncAddressDestroy (cust->shipaddr); g_list_free (cust->jobs); - remObj (cust); - if (cust->terms) gncBillTermDecRef (cust->terms); if (cust->taxtable) gncTaxTableDecRef (cust->taxtable); + qof_instance_release (&cust->inst); g_free (cust); } +GncCustomer * +gncCustomerObtainTwin (GncCustomer *from, QofBook *book) +{ + GncCustomer *cust; + if (!from) return NULL; + + cust = (GncCustomer *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!cust) + { + cust = gncCloneCustomer (from, book); + } + return cust; +} + +/* ============================================================== */ /* Set Functions */ #define SET_STR(obj, member, str) { \ - char * tmp; \ - \ - if (!safe_strcmp (member, str)) return; \ - gncCustomerBeginEdit (obj); \ - tmp = CACHE_INSERT (str); \ - CACHE_REMOVE (member); \ - member = tmp; \ - } + char * tmp; \ + \ + if (!safe_strcmp (member, str)) return; \ + gncCustomerBeginEdit (obj); \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } void gncCustomerSetID (GncCustomer *cust, const char *id) { @@ -172,18 +255,6 @@ void gncCustomerSetNotes (GncCustomer *cust, const char *notes) gncCustomerCommitEdit (cust); } -void gncCustomerSetGUID (GncCustomer *cust, const GUID *guid) -{ - if (!cust || !guid) return; - if (guid_equal (guid, &cust->guid)) return; - - gncCustomerBeginEdit (cust); - remObj (cust); - cust->guid = *guid; - addObj (cust); - gncCustomerCommitEdit (cust); -} - void gncCustomerSetTerms (GncCustomer *cust, GncBillTerm *terms) { if (!cust) return; @@ -282,9 +353,9 @@ void gncCustomerAddJob (GncCustomer *cust, GncJob *job) if (g_list_index(cust->jobs, job) == -1) cust->jobs = g_list_insert_sorted (cust->jobs, job, - (GCompareFunc)gncJobCompare); + (GCompareFunc)gncJobCompare); - gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_MODIFY); } void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job) @@ -301,47 +372,42 @@ void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job) cust->jobs = g_list_remove_link (cust->jobs, node); g_list_free_1 (node); } - gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_MODIFY); } void gncCustomerBeginEdit (GncCustomer *cust) { - GNC_BEGIN_EDIT (cust, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&cust->inst); } -static void gncCustomerOnError (GncCustomer *cust, QofBackendError errcode) +static inline void gncCustomerOnError (QofInstance *inst, QofBackendError errcode) { PERR("Customer QofBackend Failure: %d", errcode); } -static void gncCustomerOnDone (GncCustomer *cust) +static inline void gncCustomerOnDone (QofInstance *inst) { - cust->dirty = FALSE; + GncCustomer *cust = (GncCustomer *) inst; gncAddressClearDirty (cust->addr); gncAddressClearDirty (cust->shipaddr); } +static inline void cust_free (QofInstance *inst) +{ + GncCustomer *cust = (GncCustomer *) inst; + gncCustomerFree (cust); +} + void gncCustomerCommitEdit (GncCustomer *cust) { - GNC_COMMIT_EDIT_PART1 (cust); - GNC_COMMIT_EDIT_PART2 (cust, _GNC_MOD_NAME, gncCustomerOnError, - gncCustomerOnDone, gncCustomerFree); + GNC_COMMIT_EDIT_PART1 (&cust->inst); + GNC_COMMIT_EDIT_PART2 (&cust->inst, gncCustomerOnError, + gncCustomerOnDone, cust_free); } +/* ============================================================== */ /* Get Functions */ -QofBook * gncCustomerGetBook (GncCustomer *cust) -{ - if (!cust) return NULL; - return cust->book; -} - -const GUID * gncCustomerGetGUID (GncCustomer *cust) -{ - if (!cust) return NULL; - return &cust->guid; -} - const char * gncCustomerGetID (GncCustomer *cust) { if (!cust) return NULL; @@ -431,39 +497,18 @@ GList * gncCustomerGetJoblist (GncCustomer *cust, gboolean show_all) for (iterator = cust->jobs; iterator; iterator=iterator->next) { GncJob *j = iterator->data; if (gncJobGetActive (j)) - list = g_list_append (list, j); + list = g_list_append (list, j); } return list; } } -GUID gncCustomerRetGUID (GncCustomer *customer) -{ - if (!customer) - return *guid_null(); - - return customer->guid; -} - -GncCustomer * gncCustomerLookupDirect (GUID guid, QofBook *book) -{ - if (!book) return NULL; - return gncCustomerLookup (book, &guid); -} - -GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} - gboolean gncCustomerIsDirty (GncCustomer *cust) { if (!cust) return FALSE; - return (cust->dirty || - gncAddressIsDirty (cust->addr) || - gncAddressIsDirty (cust->shipaddr)); + return (cust->inst.dirty || + gncAddressIsDirty (cust->addr) || + gncAddressIsDirty (cust->shipaddr)); } /* Other functions */ @@ -477,85 +522,47 @@ int gncCustomerCompare (GncCustomer *a, GncCustomer *b) return(strcmp(a->name, b->name)); } +/* ============================================================== */ /* Package-Private functions */ - -static void addObj (GncCustomer *cust) -{ - gncBusinessAddObject (cust->book, _GNC_MOD_NAME, cust, &cust->guid); -} - -static void remObj (GncCustomer *cust) -{ - gncBusinessRemoveObject (cust->book, _GNC_MOD_NAME, &cust->guid); -} - -static void _gncCustomerCreate (QofBook *book) -{ - gncBusinessCreate (book, _GNC_MOD_NAME); -} - -static void _gncCustomerDestroy (QofBook *book) -{ - return gncBusinessDestroy (book, _GNC_MOD_NAME); -} - -static gboolean _gncCustomerIsDirty (QofBook *book) -{ - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncCustomerMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncCustomerForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - static const char * _gncCustomerPrintable (gpointer item) { - GncCustomer *c; - + GncCustomer *c = item; if (!item) return NULL; - - c = item; return c->name; } -static QofObject gncCustomerDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Customer", - _gncCustomerCreate, - _gncCustomerDestroy, - _gncCustomerIsDirty, - _gncCustomerMarkClean, - _gncCustomerForeach, - _gncCustomerPrintable, +static QofObject gncCustomerDesc = +{ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Customer", + book_begin: NULL, + book_end: NULL, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: _gncCustomerPrintable, }; gboolean gncCustomerRegister (void) { - static QofQueryObject params[] = { - { CUSTOMER_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncCustomerGetID }, - { CUSTOMER_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncCustomerGetName }, - { CUSTOMER_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetAddr }, - { CUSTOMER_SHIPADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetShipAddr }, - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncCustomerGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncCustomerGetGUID }, - { QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncCustomerGetActive }, + static QofParam params[] = { + { CUSTOMER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetID, NULL }, + { CUSTOMER_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetName, NULL }, + { CUSTOMER_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetAddr, NULL }, + { CUSTOMER_SHIPADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetShipAddr, NULL }, + { QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncCustomerGetActive, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncCustomerCompare,params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncCustomerCompare,params); return qof_object_register (&gncCustomerDesc); } gint64 gncCustomerNextID (QofBook *book) { - return gnc_book_get_counter (book, _GNC_MOD_NAME); + return qof_book_get_counter (book, _GNC_MOD_NAME); } diff --git a/src/business/business-core/gncCustomer.h b/src/business/business-core/gncCustomer.h index 8c2c4d515d..ee9fe90259 100644 --- a/src/business/business-core/gncCustomer.h +++ b/src/business/business-core/gncCustomer.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncCustomer.h -- the Core Customer Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncCustomer.h -- the Core Customer Interface * Copyright (C) 2001,2002 Derek Atkins * Author: Derek Atkins */ @@ -9,15 +30,20 @@ typedef struct _gncCustomer GncCustomer; -#include "gnc-book.h" +#include "qofbook.h" +#include "qofid.h" +#include "qofinstance.h" #include "gncAddress.h" #include "gncBillTerm.h" #include "gncTaxTable.h" #include "gncJob.h" #include "gnc-numeric.h" +#include "kvp_frame.h" -#define GNC_CUSTOMER_MODULE_NAME "gncCustomer" +#define GNC_ID_CUSTOMER "gncCustomer" +#define GNC_IS_CUSTOMER(obj) (QOF_CHECK_TYPE((obj), GNC_ID_CUSTOMER)) +#define GNC_CUSTOMER(obj) (QOF_CHECK_CAST((obj), GNC_ID_CUSTOMER, GncCustomer)) /* Create/Destroy Functions */ @@ -46,9 +72,15 @@ void gncCustomerBeginEdit (GncCustomer *customer); void gncCustomerCommitEdit (GncCustomer *customer); /* Get Functions */ +/** Return a pointer to the instance gncCustomer that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid); + */ +#define gncCustomerLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_CUSTOMER, GncCustomer) -QofBook * gncCustomerGetBook (GncCustomer *customer); -const GUID * gncCustomerGetGUID (GncCustomer *customer); const char * gncCustomerGetID (GncCustomer *customer); const char * gncCustomerGetName (GncCustomer *customer); GncAddress * gncCustomerGetAddr (GncCustomer *customer); @@ -64,12 +96,10 @@ gnc_commodity * gncCustomerGetCurrency (GncCustomer *customer); gboolean gncCustomerGetTaxTableOverride (GncCustomer *customer); GncTaxTable* gncCustomerGetTaxTable (GncCustomer *customer); +KvpFrame *gncCustomerGetSlots (GncCustomer *customer); GList * gncCustomerGetJoblist (GncCustomer *customer, gboolean show_all); -GUID gncCustomerRetGUID (GncCustomer *customer); -GncCustomer * gncCustomerLookupDirect (GUID guid, QofBook *book); -GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid); gboolean gncCustomerIsDirty (GncCustomer *customer); int gncCustomerCompare (GncCustomer *a, GncCustomer *b); @@ -79,4 +109,10 @@ int gncCustomerCompare (GncCustomer *a, GncCustomer *b); #define CUSTOMER_ADDR "addr" #define CUSTOMER_SHIPADDR "shipaddr" +/* deprecated functions, should be removed */ +#define gncCustomerGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x)) +#define gncCustomerRetGUID(x) (*(qof_instance_get_guid(QOF_INSTANCE(x)))) +#define gncCustomerGetBook(x) qof_instance_get_book(QOF_INSTANCE(x)) +#define gncCustomerLookupDirect(g,b) gncCustomerLookup((b), &(g)) + #endif /* GNC_CUSTOMER_H_ */ diff --git a/src/business/business-core/gncCustomerP.h b/src/business/business-core/gncCustomerP.h index 426addcbcc..4389b8516c 100644 --- a/src/business/business-core/gncCustomerP.h +++ b/src/business/business-core/gncCustomerP.h @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncCustomerP.h -- the Core Customer Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncCustomerP.h -- the Core Customer Interface * Copyright (C) 2001 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -8,9 +30,30 @@ #define GNC_CUSTOMERP_H_ #include "gncCustomer.h" +#include "qofid-p.h" gboolean gncCustomerRegister (void); gint64 gncCustomerNextID (QofBook *book); -void gncCustomerSetGUID (GncCustomer *customer, const GUID *guid); + +/** The gncCloneCustomer() routine makes a copy of the indicated + * customer, placing it in the indicated book. It copies + * the addresses, credits, currency, billing terms and jobs. + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ +GncCustomer * gncCloneCustomer (GncCustomer *from, QofBook *book); + +/** The gncCustomerObtainTwin() will find the 'twin' of the + * indicated customer in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneCustomer()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncCustomer * gncCustomerObtainTwin (GncCustomer *from, QofBook *book); + +#define gncCustomerSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G)) #endif /* GNC_CUSTOMERP_H_ */ diff --git a/src/business/business-core/gncEmployee.c b/src/business/business-core/gncEmployee.c index 78d1115224..95e1e36f92 100644 --- a/src/business/business-core/gncEmployee.c +++ b/src/business/business-core/gncEmployee.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncEmployee.c -- the Core Employee Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncEmployee.c -- the Core Employee Interface * Copyright (C) 2001,2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -10,64 +32,62 @@ #include #include "guid.h" +#include "qofbook.h" +#include "qofclass.h" +#include "qofid.h" +#include "qofid-p.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" +#include "qofquery.h" +#include "qofquerycore.h" + +#include "Account.h" #include "messages.h" -#include "gnc-book.h" #include "gnc-commodity.h" #include "gnc-engine-util.h" -#include "qofid.h" -#include "qofobject.h" -#include "qofquerycore.h" -#include "qofquery.h" -#include "qofqueryobject.h" #include "gnc-event-p.h" #include "gnc-be-utils.h" -#include "qofid-p.h" +#include "gncAddressP.h" #include "gncBusiness.h" #include "gncEmployee.h" #include "gncEmployeeP.h" -#include "gncAddress.h" -struct _gncEmployee { - QofBook * book; - GUID guid; - char * id; - char * username; - char * language; - char * acl; - GncAddress * addr; +struct _gncEmployee +{ + QofInstance inst; + char * id; + char * username; + GncAddress * addr; gnc_commodity * currency; - gnc_numeric workday; - gnc_numeric rate; - gboolean active; - gboolean dirty; + gboolean active; + + char * language; + char * acl; + gnc_numeric workday; + gnc_numeric rate; - Account * ccard_acc; - - int editlevel; - gboolean do_free; + Account * ccard_acc; }; -static short module = MOD_BUSINESS; +static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_EMPLOYEE_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_EMPLOYEE #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 addObj (GncEmployee *employee); -static void remObj (GncEmployee *employee); - G_INLINE_FUNC void mark_employee (GncEmployee *employee); G_INLINE_FUNC void mark_employee (GncEmployee *employee) { - employee->dirty = TRUE; - gncBusinessSetDirtyFlag (employee->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&employee->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + employee->inst.dirty = TRUE; + qof_collection_mark_dirty (employee->inst.entity.collection); + gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_MODIFY); } +/* ============================================================== */ /* Create/Destroy Functions */ GncEmployee *gncEmployeeCreate (QofBook *book) @@ -77,22 +97,18 @@ GncEmployee *gncEmployeeCreate (QofBook *book) if (!book) return NULL; employee = g_new0 (GncEmployee, 1); - employee->book = book; - employee->dirty = FALSE; - + qof_instance_init (&employee->inst, _GNC_MOD_NAME, book); + employee->id = CACHE_INSERT (""); employee->username = CACHE_INSERT (""); employee->language = CACHE_INSERT (""); employee->acl = CACHE_INSERT (""); - employee->addr = gncAddressCreate (book, &employee->guid, _GNC_MOD_NAME); + employee->addr = gncAddressCreate (book, &employee->inst.entity); employee->workday = gnc_numeric_zero(); employee->rate = gnc_numeric_zero(); employee->active = TRUE; - qof_entity_guid_new (qof_book_get_entity_table (book), &employee->guid); - addObj (employee); - - gnc_engine_generate_event (&employee->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_CREATE); return employee; } @@ -100,7 +116,7 @@ GncEmployee *gncEmployeeCreate (QofBook *book) void gncEmployeeDestroy (GncEmployee *employee) { if (!employee) return; - employee->do_free = TRUE; + employee->inst.do_free = TRUE; gncEmployeeCommitEdit(employee); } @@ -108,7 +124,7 @@ static void gncEmployeeFree (GncEmployee *employee) { if (!employee) return; - gnc_engine_generate_event (&employee->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (employee->id); CACHE_REMOVE (employee->username); @@ -116,21 +132,64 @@ static void gncEmployeeFree (GncEmployee *employee) CACHE_REMOVE (employee->acl); gncAddressDestroy (employee->addr); - remObj (employee); + qof_instance_release (&employee->inst); g_free (employee); } +GncEmployee * +gncCloneEmployee (GncEmployee *from, QofBook *book) +{ + GncEmployee *employee; + if (!book || !from) return NULL; + + employee = g_new0 (GncEmployee, 1); + qof_instance_init(&employee->inst, _GNC_MOD_NAME, book); + qof_instance_gemini (&employee->inst, &from->inst); + + employee->id = CACHE_INSERT (from->id); + employee->username = CACHE_INSERT (from->username); + employee->language = CACHE_INSERT (from->language); + employee->acl = CACHE_INSERT (from->acl); + employee->addr = gncCloneAddress (from->addr, &employee->inst.entity, book); + employee->workday = from->workday; + employee->rate = from->rate; + employee->active = from->active; + employee->currency = gnc_commodity_obtain_twin(from->currency, book); + employee->ccard_acc = + GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book)); + + gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_CREATE); + + return employee; +} + +GncEmployee * +gncEmployeeObtainTwin (GncEmployee *from, QofBook *book) +{ + GncEmployee *employee; + if (!book) return NULL; + + employee = (GncEmployee *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!employee) + { + employee = gncCloneEmployee (from, book); + } + + return employee; +} + +/* ============================================================== */ /* Set Functions */ #define SET_STR(obj, member, str) { \ - char * tmp; \ - \ - if (!safe_strcmp (member, str)) return; \ - gncEmployeeBeginEdit (obj); \ - tmp = CACHE_INSERT (str); \ - CACHE_REMOVE (member); \ - member = tmp; \ - } + char * tmp; \ + \ + if (!safe_strcmp (member, str)) return; \ + gncEmployeeBeginEdit (obj); \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } void gncEmployeeSetID (GncEmployee *employee, const char *id) { @@ -159,17 +218,6 @@ void gncEmployeeSetLanguage (GncEmployee *employee, const char *language) gncEmployeeCommitEdit (employee); } -void gncEmployeeSetGUID (GncEmployee *employee, const GUID *guid) -{ - if (!employee || !guid) return; - if (guid_equal (guid, &employee->guid)) return; - gncEmployeeBeginEdit (employee); - remObj (employee); - employee->guid = *guid; - addObj (employee); - gncEmployeeCommitEdit (employee); -} - void gncEmployeeSetAcl (GncEmployee *employee, const char *acl) { if (!employee) return; @@ -231,20 +279,8 @@ void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc) gncEmployeeCommitEdit (employee); } +/* ============================================================== */ /* Get Functions */ - -QofBook * gncEmployeeGetBook (GncEmployee *employee) -{ - if (!employee) return NULL; - return employee->book; -} - -const GUID * gncEmployeeGetGUID (GncEmployee *employee) -{ - if (!employee) return NULL; - return &employee->guid; -} - const char * gncEmployeeGetID (GncEmployee *employee) { if (!employee) return NULL; @@ -305,56 +341,43 @@ Account * gncEmployeeGetCCard (GncEmployee *employee) return employee->ccard_acc; } -GncEmployee * gncEmployeeLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} - -GUID gncEmployeeRetGUID (GncEmployee *employee) -{ - if (!employee) - return *guid_null(); - - return employee->guid; -} - -GncEmployee * gncEmployeeLookupDirect (GUID guid, QofBook *book) -{ - if (!book) return NULL; - return gncEmployeeLookup (book, &guid); -} - gboolean gncEmployeeIsDirty (GncEmployee *employee) { if (!employee) return FALSE; - return (employee->dirty || gncAddressIsDirty (employee->addr)); + return (employee->inst.dirty || gncAddressIsDirty (employee->addr)); } void gncEmployeeBeginEdit (GncEmployee *employee) { - GNC_BEGIN_EDIT (employee, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&employee->inst); } -static void gncEmployeeOnError (GncEmployee *employee, QofBackendError errcode) +static inline void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode) { PERR("Employee QofBackend Failure: %d", errcode); } -static void gncEmployeeOnDone (GncEmployee *employee) +static inline void gncEmployeeOnDone (QofInstance *inst) { - employee->dirty = FALSE; + GncEmployee *employee = (GncEmployee *) inst; gncAddressClearDirty (employee->addr); } -void gncEmployeeCommitEdit (GncEmployee *employee) +static inline void emp_free (QofInstance *inst) { - GNC_COMMIT_EDIT_PART1 (employee); - GNC_COMMIT_EDIT_PART2 (employee, _GNC_MOD_NAME, gncEmployeeOnError, - gncEmployeeOnDone, gncEmployeeFree); + GncEmployee *employee = (GncEmployee *) inst; + gncEmployeeFree (employee); } + +void gncEmployeeCommitEdit (GncEmployee *employee) +{ + GNC_COMMIT_EDIT_PART1 (&employee->inst); + GNC_COMMIT_EDIT_PART2 (&employee->inst, gncEmployeeOnError, + gncEmployeeOnDone, emp_free); +} + +/* ============================================================== */ /* Other functions */ int gncEmployeeCompare (GncEmployee *a, GncEmployee *b) @@ -368,83 +391,44 @@ int gncEmployeeCompare (GncEmployee *a, GncEmployee *b) /* Package-Private functions */ -static void addObj (GncEmployee *employee) -{ - gncBusinessAddObject (employee->book, _GNC_MOD_NAME, employee, - &employee->guid); -} - -static void remObj (GncEmployee *employee) -{ - gncBusinessRemoveObject (employee->book, _GNC_MOD_NAME, &employee->guid); -} - -static void _gncEmployeeCreate (QofBook *book) -{ - gncBusinessCreate (book, _GNC_MOD_NAME); -} - -static void _gncEmployeeDestroy (QofBook *book) -{ - gncBusinessDestroy (book, _GNC_MOD_NAME); -} - -static gboolean _gncEmployeeIsDirty (QofBook *book) -{ - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncEmployeeMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncEmployeeForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - static const char * _gncEmployeePrintable (gpointer item) { - GncEmployee *v; - + GncEmployee *v = item; if (!item) return NULL; - - v = item; return gncAddressGetName(v->addr); } -static QofObject gncEmployeeDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Employee", - _gncEmployeeCreate, - _gncEmployeeDestroy, - _gncEmployeeIsDirty, - _gncEmployeeMarkClean, - _gncEmployeeForeach, - _gncEmployeePrintable +static QofObject gncEmployeeDesc = +{ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Employee", + book_begin: NULL, + book_end: NULL, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: _gncEmployeePrintable, }; gboolean gncEmployeeRegister (void) { - static QofQueryObject params[] = { - { EMPLOYEE_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEmployeeGetID }, - { EMPLOYEE_USERNAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEmployeeGetUsername }, - { EMPLOYEE_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncEmployeeGetAddr }, - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncEmployeeGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncEmployeeGetGUID }, - { QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive }, + static QofParam params[] = { + { EMPLOYEE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetID, NULL }, + { EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername, NULL }, + { EMPLOYEE_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncEmployeeGetAddr, NULL }, + { QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare,params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare,params); return qof_object_register (&gncEmployeeDesc); } gint64 gncEmployeeNextID (QofBook *book) { - return gnc_book_get_counter (book, _GNC_MOD_NAME); + return qof_book_get_counter (book, _GNC_MOD_NAME); } diff --git a/src/business/business-core/gncEmployee.h b/src/business/business-core/gncEmployee.h index b2d3073d41..67b714aab0 100644 --- a/src/business/business-core/gncEmployee.h +++ b/src/business/business-core/gncEmployee.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncEmployee.h -- the Core Employee Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncEmployee.h -- the Core Employee Interface * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ @@ -9,11 +30,15 @@ typedef struct _gncEmployee GncEmployee; -#include "gnc-book.h" +#include "qofbook.h" +#include "qofid.h" + #include "gncAddress.h" #include "Account.h" -#define GNC_EMPLOYEE_MODULE_NAME "gncEmployee" +#define GNC_ID_EMPLOYEE "gncEmployee" +#define GNC_IS_EMPLOYEE(obj) (QOF_CHECK_TYPE((obj), GNC_ID_EMPLOYEE)) +#define GNC_EMPLOYEE(obj) (QOF_CHECK_CAST((obj), GNC_ID_EMPLOYEE, GncEmployee)) /* Create/Destroy Functions */ @@ -35,7 +60,6 @@ void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc); /* Get Functions */ QofBook * gncEmployeeGetBook (GncEmployee *employee); -const GUID * gncEmployeeGetGUID (GncEmployee *employee); const char * gncEmployeeGetID (GncEmployee *employee); const char * gncEmployeeGetUsername (GncEmployee *employee); GncAddress * gncEmployeeGetAddr (GncEmployee *employee); @@ -47,11 +71,18 @@ gnc_commodity * gncEmployeeGetCurrency (GncEmployee *employee); gboolean gncEmployeeGetActive (GncEmployee *employee); Account * gncEmployeeGetCCard (GncEmployee *employee); -GncEmployee * gncEmployeeLookup (QofBook *book, const GUID *guid); + +/** Return a pointer to the instance gncEmployee that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncEmployee * gncEmployeeLookup (QofBook *book, const GUID *guid); + */ +#define gncEmployeeLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_EMPLOYEE, GncEmployee) + gboolean gncEmployeeIsDirty (GncEmployee *employee); -GUID gncEmployeeRetGUID (GncEmployee *employee); -GncEmployee * gncEmployeeLookupDirect (GUID guid, QofBook *book); void gncEmployeeBeginEdit (GncEmployee *employee); void gncEmployeeCommitEdit (GncEmployee *employee); @@ -61,4 +92,9 @@ int gncEmployeeCompare (GncEmployee *a, GncEmployee *b); #define EMPLOYEE_USERNAME "username" #define EMPLOYEE_ADDR "addr" +/** deprecated routines */ +#define gncEmployeeGetGUID(E) qof_entity_get_guid(QOF_ENTITY(E)) +#define gncEmployeeRetGUID(E) (*(qof_entity_get_guid(QOF_ENTITY(E)))) +#define gncEmployeeLookupDirect(G,B) gncEmployeeLookup((B),&(G)) + #endif /* GNC_EMPLOYEE_H_ */ diff --git a/src/business/business-core/gncEmployeeP.h b/src/business/business-core/gncEmployeeP.h index 2f8aebb199..412f62b7c6 100644 --- a/src/business/business-core/gncEmployeeP.h +++ b/src/business/business-core/gncEmployeeP.h @@ -1,6 +1,28 @@ -/* +/********************************************************************\ * gncEmployeeP.h -- the Core Employee Interface + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + +/* * Copyright (C) 2001 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -8,9 +30,34 @@ #define GNC_EMPLOYEEP_H_ #include "gncEmployee.h" +#include "qofid-p.h" gboolean gncEmployeeRegister (void); gint64 gncEmployeeNextID (QofBook *book); -void gncEmployeeSetGUID (GncEmployee *employee, const GUID *guid); + +/** The gncCloneEmployee() routine makes a copy of the indicated + * employee, placing it in the indicated book. It copies + * the username, address, currency, ccard account, etc. + * It also copies (as needed) both parents and children, so that + * the parent-child relationship is correctly mirrored in the + * clone. + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ + +GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *); + +/** The gncEmployeeObtainTwin() will find the 'twin' of the + * indicated employee in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneEmployee()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncEmployee * gncEmployeeObtainTwin (GncEmployee *from, QofBook *book); + +#define gncEmployeeSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G)) #endif /* GNC_EMPLOYEEP_H_ */ diff --git a/src/business/business-core/gncEntry.c b/src/business/business-core/gncEntry.c index 733f074fab..273860e882 100644 --- a/src/business/business-core/gncEntry.c +++ b/src/business/business-core/gncEntry.c @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncEntry.c -- the Core Business Entry Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncEntry.c -- the Core Business Entry Interface * Copyright (C) 2001,2002 Derek Atkins * Author: Derek Atkins */ @@ -9,17 +30,21 @@ #include #include "messages.h" -#include "gnc-book.h" #include "gnc-commodity.h" #include "gnc-engine-util.h" #include "gnc-event-p.h" #include "gnc-numeric.h" -#include "qofid.h" -#include "qofquerycore.h" -#include "qofquery.h" -#include "qofqueryobject.h" #include "gnc-be-utils.h" + +#include "qofbook.h" +#include "qofclass.h" +#include "qofid.h" #include "qofid-p.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" +#include "qofquery.h" +#include "qofquerycore.h" #include "gncBusiness.h" #include "gncEntry.h" @@ -27,10 +52,10 @@ #include "gncInvoice.h" #include "gncOrder.h" -struct _gncEntry { - QofBook * book; +struct _gncEntry +{ + QofInstance inst; - GUID guid; Timespec date; Timespec date_entered; char * desc; @@ -65,12 +90,7 @@ struct _gncEntry { GncInvoice * invoice; GncInvoice * bill; - int editlevel; - gboolean do_free; - gboolean dirty; - /* CACHED VALUES */ - gboolean values_dirty; /* customer invoice */ @@ -149,7 +169,7 @@ gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type } #undef GNC_RETURN_ON_MATCH -#define _GNC_MOD_NAME GNC_ENTRY_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_ENTRY #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)); @@ -164,19 +184,16 @@ gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type member = tmp; \ } -static void addObj (GncEntry *entry); -static void remObj (GncEntry *entry); - G_INLINE_FUNC void mark_entry (GncEntry *entry); G_INLINE_FUNC void mark_entry (GncEntry *entry) { - entry->dirty = TRUE; - gncBusinessSetDirtyFlag (entry->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&entry->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + entry->inst.dirty = TRUE; + qof_collection_mark_dirty (entry->inst.entity.collection); + gnc_engine_gen_event (&entry->inst.entity, GNC_EVENT_MODIFY); } +/* ================================================================ */ /* Create/Destroy Functions */ GncEntry *gncEntryCreate (QofBook *book) @@ -187,7 +204,7 @@ GncEntry *gncEntryCreate (QofBook *book) if (!book) return NULL; entry = g_new0 (GncEntry, 1); - entry->book = book; + qof_instance_init (&entry->inst, _GNC_MOD_NAME, book); entry->desc = CACHE_INSERT (""); entry->action = CACHE_INSERT (""); @@ -207,10 +224,7 @@ GncEntry *gncEntryCreate (QofBook *book) entry->values_dirty = TRUE; - qof_entity_guid_new (qof_book_get_entity_table (book), &entry->guid); - addObj (entry); - - gnc_engine_generate_event (&entry->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&entry->inst.entity, GNC_EVENT_CREATE); return entry; } @@ -218,7 +232,7 @@ GncEntry *gncEntryCreate (QofBook *book) void gncEntryDestroy (GncEntry *entry) { if (!entry) return; - entry->do_free = TRUE; + entry->inst.do_free = TRUE; gncEntryCommitEdit(entry); } @@ -226,7 +240,7 @@ static void gncEntryFree (GncEntry *entry) { if (!entry) return; - gnc_engine_generate_event (&entry->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&entry->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (entry->desc); CACHE_REMOVE (entry->action); @@ -239,25 +253,37 @@ static void gncEntryFree (GncEntry *entry) gncTaxTableDecRef (entry->i_tax_table); if (entry->b_tax_table) gncTaxTableDecRef (entry->b_tax_table); - remObj (entry); + qof_instance_release (&entry->inst); g_free (entry); } -/* Set Functions */ - -void gncEntrySetGUID (GncEntry *entry, const GUID *guid) +GncEntry * +gncCloneEntry (GncEntry *from, QofBook *book) { - if (!entry || !guid) return; - if (guid_equal (guid, &entry->guid)) return; - - gncEntryBeginEdit (entry); - remObj (entry); - entry->guid = *guid; - addObj (entry); - gncEntryCommitEdit (entry); + /* XXX unfinished */ + return NULL; } +GncEntry * +gncEntryObtainTwin (GncEntry *from, QofBook *book) +{ + GncEntry *entry; + if (!book) return NULL; + + entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!entry) + { + entry = gncCloneEntry (from, book); + } + + return entry; +} + + +/* ================================================================ */ +/* Set Functions */ + void gncEntrySetDate (GncEntry *entry, Timespec date) { if (!entry) return; @@ -512,7 +538,7 @@ void gncEntrySetOrder (GncEntry *entry, GncOrder *order) /* Generate an event modifying the Order's end-owner */ #if 0 - gnc_engine_generate_event (gncOwnerGetEndGUID (gncOrderGetOwner (order)), + gnc_engine_gen_event (gncOwnerGetEndGUID (gncOrderGetOwner (order)), GNC_EVENT_MODIFY); #endif } @@ -539,12 +565,6 @@ void gncEntrySetBill (GncEntry *entry, GncInvoice *bill) gncEntryCommitEdit (entry); } -void gncEntrySetDirty (GncEntry *entry, gboolean dirty) -{ - if (!entry) return; - entry->dirty = dirty; -} - void gncEntryCopy (const GncEntry *src, GncEntry *dest) { if (!src || !dest) return; @@ -592,20 +612,9 @@ void gncEntryCopy (const GncEntry *src, GncEntry *dest) gncEntryCommitEdit (dest); } +/* ================================================================ */ /* Get Functions */ -QofBook * gncEntryGetBook (GncEntry *entry) -{ - if (!entry) return NULL; - return entry->book; -} - -const GUID * gncEntryGetGUID (GncEntry *entry) -{ - if (!entry) return NULL; - return &(entry->guid); -} - Timespec gncEntryGetDate (GncEntry *entry) { Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0; @@ -762,13 +771,7 @@ GncOrder * gncEntryGetOrder (GncEntry *entry) return entry->order; } -GncEntry * gncEntryLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} - +/* ================================================================ */ /* * This is the logic of computing the total for an Entry, so you know * what values to put into various Splits or to display in the ledger. @@ -1101,32 +1104,38 @@ gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv) return (is_inv ? entry->i_disc_value_rounded : gnc_numeric_zero()); } +/* XXXX this exsitnace of this routine is just wrong */ gboolean gncEntryIsOpen (GncEntry *entry) { if (!entry) return FALSE; - return (entry->editlevel > 0); + return (entry->inst.editlevel > 0); } +/* ================================================================ */ + void gncEntryBeginEdit (GncEntry *entry) { - GNC_BEGIN_EDIT (entry, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&entry->inst); } -static void gncEntryOnError (GncEntry *entry, QofBackendError errcode) +static inline void gncEntryOnError (QofInstance *entry, QofBackendError errcode) { PERR("Entry QofBackend Failure: %d", errcode); } -static void gncEntryOnDone (GncEntry *entry) +static inline void gncEntryOnDone (QofInstance *inst) {} + +static inline void entry_free (QofInstance *inst) { - entry->dirty = FALSE; + GncEntry *entry = (GncEntry *)inst; + gncEntryFree (entry); } void gncEntryCommitEdit (GncEntry *entry) { - GNC_COMMIT_EDIT_PART1 (entry); - GNC_COMMIT_EDIT_PART2 (entry, _GNC_MOD_NAME, gncEntryOnError, - gncEntryOnDone, gncEntryFree); + GNC_COMMIT_EDIT_PART1 (&entry->inst); + GNC_COMMIT_EDIT_PART2 (&entry->inst, gncEntryOnError, + gncEntryOnDone, entry_free); } int gncEntryCompare (GncEntry *a, GncEntry *b) @@ -1149,81 +1158,47 @@ int gncEntryCompare (GncEntry *a, GncEntry *b) compare = safe_strcmp (a->action, b->action); if (compare) return compare; - return guid_compare (&(a->guid), &(b->guid)); + return guid_compare (&(a->inst.entity.guid), &(b->inst.entity.guid)); } -/* Package-Private functions */ +/* ============================================================= */ +/* Object declaration */ -static void addObj (GncEntry *entry) +static QofObject gncEntryDesc = { - gncBusinessAddObject (entry->book, _GNC_MOD_NAME, entry, &entry->guid); -} - -static void remObj (GncEntry *entry) -{ - gncBusinessRemoveObject (entry->book, _GNC_MOD_NAME, &entry->guid); -} - -static void _gncEntryCreate (QofBook *book) -{ - gncBusinessCreate (book, _GNC_MOD_NAME); -} - -static void _gncEntryDestroy (QofBook *book) -{ - gncBusinessDestroy (book, _GNC_MOD_NAME); -} - -static gboolean _gncEntryIsDirty (QofBook *book) -{ - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncEntryMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncEntryForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - -static QofObject gncEntryDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Order/Invoice/Bill Entry", - _gncEntryCreate, - _gncEntryDestroy, - _gncEntryIsDirty, - _gncEntryMarkClean, - _gncEntryForeach, - NULL /* printable */ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Order/Invoice/Bill Entry", + book_begin: NULL, + book_end: NULL, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: NULL, }; gboolean gncEntryRegister (void) { - static QofQueryObject params[] = { - { ENTRY_DATE, QOF_QUERYCORE_DATE, (QofAccessFunc)gncEntryGetDate }, - { ENTRY_DATE_ENTERED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncEntryGetDateEntered }, - { ENTRY_DESC, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEntryGetDescription }, - { ENTRY_ACTION, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEntryGetAction }, - { ENTRY_NOTES, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEntryGetNotes }, - { ENTRY_QTY, QOF_QUERYCORE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity }, - { ENTRY_IPRICE, QOF_QUERYCORE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice }, - { ENTRY_BPRICE, QOF_QUERYCORE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice }, - { ENTRY_INVOICE, GNC_INVOICE_MODULE_NAME, (QofAccessFunc)gncEntryGetInvoice }, - { ENTRY_BILL, GNC_INVOICE_MODULE_NAME, (QofAccessFunc)gncEntryGetBill }, - { ENTRY_BILLABLE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable }, - { ENTRY_BILLTO, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncEntryGetBillTo }, - { ENTRY_ORDER, GNC_ORDER_MODULE_NAME, (QofAccessFunc)gncEntryGetOrder }, - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncEntryGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncEntryGetGUID }, + static QofParam params[] = { + { ENTRY_DATE, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDate, NULL }, + { ENTRY_DATE_ENTERED, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDateEntered, NULL }, + { ENTRY_DESC, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetDescription, NULL }, + { ENTRY_ACTION, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetAction, NULL }, + { ENTRY_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetNotes, NULL }, + { ENTRY_QTY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity, NULL }, + { ENTRY_IPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice, NULL }, + { ENTRY_BPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice, NULL }, + { ENTRY_INVOICE, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetInvoice, NULL }, + { ENTRY_BILL, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetBill, NULL }, + { ENTRY_BILLABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable, NULL }, + { ENTRY_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncEntryGetBillTo, NULL }, + { ENTRY_ORDER, GNC_ID_ORDER, (QofAccessFunc)gncEntryGetOrder, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params); return qof_object_register (&gncEntryDesc); } diff --git a/src/business/business-core/gncEntry.h b/src/business/business-core/gncEntry.h index 1aa9b38ca5..0ac83268fb 100644 --- a/src/business/business-core/gncEntry.h +++ b/src/business/business-core/gncEntry.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncEntry.h -- the Core Business Entry Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncEntry.h -- the Core Business Entry Interface * Copyright (C) 2001,2002 Derek Atkins * Author: Derek Atkins */ @@ -20,13 +41,18 @@ typedef enum { GNC_DISC_POSTTAX } GncDiscountHow; -#include "gnc-book.h" -#include "gnc-date.h" -#include "gncTaxTable.h" -#include "gncOrder.h" -#include "gncInvoice.h" +#include "qofbook.h" +#include "qofinstance.h" -#define GNC_ENTRY_MODULE_NAME "gncEntry" +#include "gnc-date.h" +#include "gncBusiness.h" +#include "gncInvoice.h" +#include "gncOrder.h" +#include "gncTaxTable.h" + +#define GNC_ID_ENTRY "gncEntry" +#define GNC_IS_ENTRY(obj) (QOF_CHECK_TYPE((obj), GNC_ID_ENTRY)) +#define GNC_ENTRY(obj) (QOF_CHECK_CAST((obj), GNC_ID_ENTRY, GncEntry)) /* How to apply the discount and taxes. There are three distinct ways to * apply them: @@ -82,8 +108,6 @@ void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type); /* GET FUNCTIONS */ /* Generic (shared) data */ -QofBook * gncEntryGetBook (GncEntry *entry); -const GUID * gncEntryGetGUID (GncEntry *entry); Timespec gncEntryGetDate (GncEntry *entry); Timespec gncEntryGetDateEntered (GncEntry *entry); const char * gncEntryGetDescription (GncEntry *entry); @@ -148,7 +172,14 @@ GncOrder * gncEntryGetOrder (GncEntry *entry); GncInvoice * gncEntryGetInvoice (GncEntry *entry); GncInvoice * gncEntryGetBill (GncEntry *entry); -GncEntry * gncEntryLookup (QofBook *book, const GUID *guid); +/** Return a pointer to the instance gncEntry that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncEntry * gncEntryLookup (QofBook *book, const GUID *guid); + */ +#define gncEntryLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_ENTRY, GncEntry) gboolean gncEntryIsOpen (GncEntry *entry); void gncEntryBeginEdit (GncEntry *entry); @@ -171,4 +202,7 @@ int gncEntryCompare (GncEntry *a, GncEntry *b); #define ENTRY_INVOICE "invoice" #define ENTRY_BILL "bill" +/* deprecated functions, should be removed */ +#define gncEntryGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x)) + #endif /* GNC_ENTRY_H_ */ diff --git a/src/business/business-core/gncEntryP.h b/src/business/business-core/gncEntryP.h index f3b63cf867..7b15a54bd4 100644 --- a/src/business/business-core/gncEntryP.h +++ b/src/business/business-core/gncEntryP.h @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncEntryP.h -- the Core Busines Entry Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncEntryP.h -- the Core Busines Entry Interface * Copyright (C) 2001 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -8,6 +30,7 @@ #define GNC_ENTRYP_H_ #include "gncEntry.h" +#include "qofid-p.h" gboolean gncEntryRegister (void); void gncEntrySetGUID (GncEntry *entry, const GUID *guid); @@ -16,4 +39,27 @@ void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice); void gncEntrySetBill (GncEntry *entry, GncInvoice *bill); void gncEntrySetDirty (GncEntry *entry, gboolean dirty); + +/** The gncCloneEntry() routine makes a copy of the indicated + * entry, placing it in the indicated book. It copies + * the whole kit-n-kaboodle. + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ + +GncEntry * gncCloneEntry (GncEntry *from, QofBook *); + +/** The gncEntryObtainTwin() will find the 'twin' of the + * indicated entry in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneEntry()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncEntry * gncEntryObtainTwin (GncEntry *from, QofBook *book); + +#define gncEntrySetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G)) + #endif /* GNC_ENTRYP_H_ */ diff --git a/src/business/business-core/gncInvoice.c b/src/business/business-core/gncInvoice.c index 1e807055c5..a92094e47b 100644 --- a/src/business/business-core/gncInvoice.c +++ b/src/business/business-core/gncInvoice.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncInvoice.c -- the Core Business Invoice * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncInvoice.c -- the Core Business Invoice * Copyright (C) 2001,2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -8,35 +30,44 @@ #include +#include "qofbook.h" +#include "qofclass.h" +#include "qofid.h" +#include "qofid-p.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" +#include "qofquerycore.h" +#include "qofquery.h" + #include "Transaction.h" #include "Account.h" #include "messages.h" #include "gnc-numeric.h" #include "kvp_frame.h" #include "gnc-engine-util.h" -#include "gnc-book.h" -#include "qofid.h" -#include "qofquerycore.h" -#include "qofquery.h" -#include "qofqueryobject.h" + #include "gnc-event-p.h" #include "gnc-lot.h" #include "gnc-be-utils.h" -#include "qofid-p.h" #include "gncBusiness.h" +#include "gncBillTermP.h" #include "gncEntry.h" #include "gncEntryP.h" +#include "gncJobP.h" #include "gncInvoice.h" #include "gncInvoiceP.h" -#include "gncOwner.h" +#include "gncOwnerP.h" -struct _gncInvoice { - QofBook *book; +struct _gncInvoice +{ + QofInstance inst; - GUID guid; char * id; char * notes; + gboolean active; + char * billing_id; char * printname; GncBillTerm * terms; @@ -54,18 +85,11 @@ struct _gncInvoice { Account * posted_acc; Transaction * posted_txn; GNCLot * posted_lot; - - gboolean active; - - int editlevel; - gboolean do_free; - - gboolean dirty; }; static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_INVOICE_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_INVOICE #define GNC_INVOICE_ID "gncInvoice" #define GNC_INVOICE_GUID "invoice-guid" @@ -83,19 +107,16 @@ static short module = MOD_BUSINESS; member = tmp; \ } -static void addObj (GncInvoice *invoice); -static void remObj (GncInvoice *invoice); - static void mark_invoice (GncInvoice *invoice); static void mark_invoice (GncInvoice *invoice) { - invoice->dirty = TRUE; - gncBusinessSetDirtyFlag (invoice->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&invoice->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + invoice->inst.dirty = TRUE; + qof_collection_mark_dirty (invoice->inst.entity.collection); + gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_MODIFY); } +/* ================================================================== */ /* Create/Destroy Functions */ GncInvoice *gncInvoiceCreate (QofBook *book) @@ -105,7 +126,7 @@ GncInvoice *gncInvoiceCreate (QofBook *book) if (!book) return NULL; invoice = g_new0 (GncInvoice, 1); - invoice->book = book; + qof_instance_init (&invoice->inst, _GNC_MOD_NAME, book); invoice->id = CACHE_INSERT (""); invoice->notes = CACHE_INSERT (""); @@ -116,10 +137,7 @@ GncInvoice *gncInvoiceCreate (QofBook *book) invoice->to_charge_amount = gnc_numeric_zero(); - qof_entity_guid_new (qof_book_get_entity_table (book), &invoice->guid); - addObj (invoice); - - gnc_engine_generate_event (&invoice->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_CREATE); return invoice; } @@ -127,7 +145,7 @@ GncInvoice *gncInvoiceCreate (QofBook *book) void gncInvoiceDestroy (GncInvoice *invoice) { if (!invoice) return; - invoice->do_free = TRUE; + invoice->inst.do_free = TRUE; gncInvoiceCommitEdit (invoice); } @@ -135,36 +153,92 @@ static void gncInvoiceFree (GncInvoice *invoice) { if (!invoice) return; - gnc_engine_generate_event (&invoice->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (invoice->id); CACHE_REMOVE (invoice->notes); CACHE_REMOVE (invoice->billing_id); g_list_free (invoice->entries); - remObj (invoice); if (invoice->printname) g_free (invoice->printname); if (invoice->terms) gncBillTermDecRef (invoice->terms); + qof_instance_release (&invoice->inst); g_free (invoice); } -/* Set Functions */ - -void gncInvoiceSetGUID (GncInvoice *invoice, const GUID *guid) +GncInvoice * +gncCloneInvoice (GncInvoice *from, QofBook *book) { - if (!invoice || !guid) return; - if (guid_equal (guid, &invoice->guid)) return; + GList *node; + GncInvoice *invoice; - gncInvoiceBeginEdit (invoice); - remObj (invoice); - invoice->guid = *guid; - addObj (invoice); - gncInvoiceCommitEdit (invoice); + if (!book) return NULL; + + invoice = g_new0 (GncInvoice, 1); + qof_instance_init (&invoice->inst, _GNC_MOD_NAME, book); + + invoice->id = CACHE_INSERT (from->id); + invoice->notes = CACHE_INSERT (from->notes); + invoice->billing_id = CACHE_INSERT (from->billing_id); + invoice->active = from->active; + + invoice->billto = gncCloneOwner (&from->billto, book); + invoice->owner = gncCloneOwner (&from->owner, book); + invoice->job = gncJobObtainTwin (from->job, book); + invoice->terms = gncBillTermObtainTwin (from->terms, book); + gncBillTermIncRef (invoice->terms); + + + invoice->to_charge_amount = from->to_charge_amount; + invoice->printname = NULL; /* that's right, NULL. See below. */ + invoice->date_opened = from->date_opened; + invoice->date_posted = from->date_posted; + + invoice->currency = gnc_commodity_obtain_twin (from->currency, book); + + invoice->entries = NULL; + for (node = g_list_last(from->entries); node; node=node->next) + { + GncEntry *entry = node->data; + entry = gncEntryObtainTwin (entry, book); + invoice->entries = g_list_prepend (invoice->entries, entry); + } + + /* XXX should probably be obtain-twin not lookup-twin */ + invoice->posted_acc = + GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->posted_acc), book)); +#if 0 +XXX not done */ + Transaction * posted_txn; + GNCLot * posted_lot; +#endif + + gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_CREATE); + + return invoice; } +GncInvoice * +gncInvoiceObtainTwin (GncInvoice *from, QofBook *book) +{ + GncInvoice *invoice; + if (!book) return NULL; + + invoice = (GncInvoice *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!invoice) + { + invoice = gncCloneInvoice (from, book); + } + + return invoice; +} + +/* ================================================================== */ +/* Set Functions */ + void gncInvoiceSetID (GncInvoice *invoice, const char *id) { if (!invoice || !id) return; @@ -276,12 +350,6 @@ void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount) gncInvoiceCommitEdit (invoice); } -void gncInvoiceSetDirty (GncInvoice *invoice, gboolean dirty) -{ - if (!invoice) return; - invoice->dirty = dirty; -} - void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn) { if (!invoice) return; @@ -365,20 +433,9 @@ void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry) mark_invoice (bill); } +/* ================================================================== */ /* Get Functions */ -QofBook * gncInvoiceGetBook (GncInvoice *invoice) -{ - if (!invoice) return NULL; - return invoice->book; -} - -const GUID * gncInvoiceGetGUID (GncInvoice *invoice) -{ - if (!invoice) return NULL; - return &(invoice->guid); -} - const char * gncInvoiceGetID (GncInvoice *invoice) { if (!invoice) return NULL; @@ -567,12 +624,6 @@ GList * gncInvoiceGetEntries (GncInvoice *invoice) return invoice->entries; } -gboolean gncInvoiceIsDirty (GncInvoice *invoice) -{ - if (!invoice) return FALSE; - return invoice->dirty; -} - static void gncInvoiceDetachFromLot (GNCLot *lot) { @@ -596,7 +647,7 @@ gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot) if (invoice->posted_lot) return; /* Cannot reset invoice's lot */ kvp = gnc_lot_get_slots (lot); - value = kvp_value_new_guid (gncInvoiceGetGUID (invoice)); + value = kvp_value_new_guid (qof_instance_get_guid (QOF_INSTANCE(invoice))); kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL); kvp_value_delete (value); gncInvoiceSetPostedLot (invoice, lot); @@ -617,9 +668,7 @@ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot) if (!value) return NULL; guid = kvp_value_get_guid (value); - - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); + return gncInvoiceLookup(book, guid); } static void @@ -635,7 +684,7 @@ gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn) xaccTransBeginEdit (txn); kvp = xaccTransGetSlots (txn); - value = kvp_value_new_guid (gncInvoiceGetGUID (invoice)); + value = kvp_value_new_guid (qof_instance_get_guid(QOF_INSTANCE(invoice))); kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL); kvp_value_delete (value); xaccTransSetTxnType (txn, TXN_TYPE_INVOICE); @@ -643,7 +692,8 @@ gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn) gncInvoiceSetPostedTxn (invoice, txn); } -GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn) +GncInvoice * +gncInvoiceGetInvoiceFromTxn (Transaction *txn) { KvpFrame *kvp; KvpValue *value; @@ -658,9 +708,7 @@ GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn) if (!value) return NULL; guid = kvp_value_get_guid (value); - - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); + return gncInvoiceLookup(book,guid); } struct lotmatch { @@ -741,10 +789,10 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, /* Create a new lot for this invoice, if we need to do so */ if (!lot) - lot = gnc_lot_new (invoice->book); + lot = gnc_lot_new (invoice->inst.book); /* Create a new transaction */ - txn = xaccMallocTransaction (invoice->book); + txn = xaccMallocTransaction (invoice->inst.book); xaccTransBeginEdit (txn); name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice))); @@ -812,7 +860,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, if (ccard_acct && gncEntryGetBillPayment (entry) == GNC_PAYMENT_CARD) { Split *split; - split = xaccMallocSplit (invoice->book); + split = xaccMallocSplit (invoice->inst.book); /* set action? */ xaccSplitSetMemo (split, gncEntryGetDescription (entry)); xaccSplitSetAction (split, type); @@ -846,7 +894,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, Split *split; GncAccountValue *acc_val = iter->data; - split = xaccMallocSplit (invoice->book); + split = xaccMallocSplit (invoice->inst.book); /* set action and memo? */ xaccSplitSetMemo (split, memo); @@ -865,7 +913,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, * we should make that now.. */ if (ccard_acct && !gnc_numeric_zero_p (invoice->to_charge_amount)) { - Split *split = xaccMallocSplit (invoice->book); + Split *split = xaccMallocSplit (invoice->inst.book); /* Set memo. action? */ xaccSplitSetMemo (split, _("Extra to Charge Card")); @@ -885,7 +933,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, /* Now create the Posted split (which is negative -- it's a credit) */ { - Split *split = xaccMallocSplit (invoice->book); + Split *split = xaccMallocSplit (invoice->inst.book); /* Set action/memo */ xaccSplitSetMemo (split, memo); @@ -928,8 +976,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, char *memo2 = _("Automatic Payment Forward"); char *action2 = _("Auto Split"); - t2 = xaccMallocTransaction (invoice->book); - lot2 = gnc_lot_new (invoice->book); + t2 = xaccMallocTransaction (invoice->inst.book); + lot2 = gnc_lot_new (invoice->inst.book); gncOwnerAttachToLot (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)), lot2); @@ -946,7 +994,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, xaccTransSetDatePostedTS (t2, post_date); /* Balance out this lot */ - split = xaccMallocSplit (invoice->book); + split = xaccMallocSplit (invoice->inst.book); xaccSplitSetMemo (split, memo2); xaccSplitSetAction (split, action2); xaccSplitSetBaseValue (split, gnc_numeric_neg (total), @@ -956,7 +1004,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc, gnc_lot_add_split (lot, split); /* And apply the pre-payment to a new lot */ - split = xaccMallocSplit (invoice->book); + split = xaccMallocSplit (invoice->inst.book); xaccSplitSetMemo (split, memo2); xaccSplitSetAction (split, action2); xaccSplitSetBaseValue (split, total, invoice->currency); @@ -1236,47 +1284,31 @@ gboolean gncInvoiceIsPaid (GncInvoice *invoice) return gnc_lot_is_closed(invoice->posted_lot); } -GUID gncInvoiceRetGUID (GncInvoice *invoice) -{ - if (!invoice) - return *guid_null(); - - return invoice->guid; -} - -GncInvoice * gncInvoiceLookupDirect (GUID guid, QofBook *book) -{ - if (!book) return NULL; - return gncInvoiceLookup (book, &guid); -} - -GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} +/* ================================================================== */ void gncInvoiceBeginEdit (GncInvoice *invoice) { - GNC_BEGIN_EDIT (invoice, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&invoice->inst); } -static void gncInvoiceOnError (GncInvoice *invoice, QofBackendError errcode) +static inline void gncInvoiceOnError (QofInstance *inst, QofBackendError errcode) { PERR("Invoice QofBackend Failure: %d", errcode); } -static void gncInvoiceOnDone (GncInvoice *invoice) +static inline void gncInvoiceOnDone (QofInstance *invoice) { } + +static inline void invoice_free (QofInstance *inst) { - invoice->dirty = FALSE; + GncInvoice *invoice = (GncInvoice *) inst; + gncInvoiceFree (invoice); } void gncInvoiceCommitEdit (GncInvoice *invoice) { - GNC_COMMIT_EDIT_PART1 (invoice); - GNC_COMMIT_EDIT_PART2 (invoice, _GNC_MOD_NAME, gncInvoiceOnError, - gncInvoiceOnDone, gncInvoiceFree); + GNC_COMMIT_EDIT_PART1 (&invoice->inst); + GNC_COMMIT_EDIT_PART2 (&invoice->inst, gncInvoiceOnError, + gncInvoiceOnDone, invoice_free); } int gncInvoiceCompare (GncInvoice *a, GncInvoice *b) @@ -1296,54 +1328,19 @@ int gncInvoiceCompare (GncInvoice *a, GncInvoice *b) compare = timespec_cmp (&(a->date_posted), &(b->date_posted)); if (compare) return compare; - return guid_compare (&(a->guid), &(b->guid)); + return guid_compare (&(a->inst.entity.guid), &(b->inst.entity.guid)); } +/* ============================================================= */ /* Package-Private functions */ -static void addObj (GncInvoice *invoice) -{ - gncBusinessAddObject (invoice->book, _GNC_MOD_NAME, invoice, &invoice->guid); -} - -static void remObj (GncInvoice *invoice) -{ - gncBusinessRemoveObject (invoice->book, _GNC_MOD_NAME, &invoice->guid); -} - -static void _gncInvoiceCreate (QofBook *book) -{ - gncBusinessCreate (book, _GNC_MOD_NAME); -} - -static void _gncInvoiceDestroy (QofBook *book) -{ - gncBusinessDestroy (book, _GNC_MOD_NAME); -} - -static gboolean _gncInvoiceIsDirty (QofBook *book) -{ - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncInvoiceMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncInvoiceForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - static const char * _gncInvoicePrintable (gpointer obj) { GncInvoice *invoice = obj; g_return_val_if_fail (invoice, NULL); - if (invoice->dirty || invoice->printname == NULL) { + if (invoice->inst.dirty || invoice->printname == NULL) { if (invoice->printname) g_free (invoice->printname); invoice->printname = @@ -1354,67 +1351,68 @@ static const char * _gncInvoicePrintable (gpointer obj) return invoice->printname; } -static QofObject gncInvoiceDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Invoice", - _gncInvoiceCreate, - _gncInvoiceDestroy, - _gncInvoiceIsDirty, - _gncInvoiceMarkClean, - _gncInvoiceForeach, - _gncInvoicePrintable, +static QofObject gncInvoiceDesc = +{ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Invoice", + book_begin: NULL, + book_end: NULL, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: _gncInvoicePrintable, }; static void reg_lot (void) { - static QofQueryObject params[] = { + static QofParam params[] = { { INVOICE_FROM_LOT, _GNC_MOD_NAME, - (QofAccessFunc)gncInvoiceGetInvoiceFromLot }, + (QofAccessFunc)gncInvoiceGetInvoiceFromLot, NULL }, { NULL }, }; - qof_query_object_register (GNC_ID_LOT, NULL, params); + qof_class_register (GNC_ID_LOT, NULL, params); } static void reg_txn (void) { - static QofQueryObject params[] = { + static QofParam params[] = { { INVOICE_FROM_TXN, _GNC_MOD_NAME, - (QofAccessFunc)gncInvoiceGetInvoiceFromTxn }, + (QofAccessFunc)gncInvoiceGetInvoiceFromTxn, NULL }, { NULL }, }; - qof_query_object_register (GNC_ID_TRANS, NULL, params); + qof_class_register (GNC_ID_TRANS, NULL, params); } gboolean gncInvoiceRegister (void) { - static QofQueryObject params[] = { - { INVOICE_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetID }, - { INVOICE_OWNER, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncInvoiceGetOwner }, - { INVOICE_OPENED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened }, - { INVOICE_DUE, QOF_QUERYCORE_DATE, (QofAccessFunc)gncInvoiceGetDateDue }, - { INVOICE_POSTED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted }, - { INVOICE_IS_POSTED, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted }, - { INVOICE_IS_PAID, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid }, - { INVOICE_BILLINGID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetBillingID }, - { INVOICE_NOTES, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetNotes }, - { INVOICE_ACC, GNC_ID_ACCOUNT, (QofAccessFunc)gncInvoiceGetPostedAcc }, - { INVOICE_POST_TXN, GNC_ID_TRANS, (QofAccessFunc)gncInvoiceGetPostedTxn }, - { INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot }, - { INVOICE_TYPE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetType }, - { INVOICE_TERMS, GNC_BILLTERM_MODULE_NAME, (QofAccessFunc)gncInvoiceGetTerms }, - { INVOICE_BILLTO, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncInvoiceGetBillTo }, - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncInvoiceGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncInvoiceGetGUID }, - { QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive }, + static QofParam params[] = { + { INVOICE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID, NULL }, + { INVOICE_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL }, + { INVOICE_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened, NULL }, + { INVOICE_DUE, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateDue, NULL }, + { INVOICE_POSTED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted, NULL }, + { INVOICE_IS_POSTED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted, NULL }, + { INVOICE_IS_PAID, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid, NULL }, + { INVOICE_BILLINGID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetBillingID, NULL }, + { INVOICE_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetNotes, NULL }, + { INVOICE_ACC, GNC_ID_ACCOUNT, (QofAccessFunc)gncInvoiceGetPostedAcc, NULL }, + { INVOICE_POST_TXN, GNC_ID_TRANS, (QofAccessFunc)gncInvoiceGetPostedTxn, NULL }, + { INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot, NULL }, + { INVOICE_TYPE, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetType, NULL }, + { INVOICE_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms, NULL }, + { INVOICE_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL }, + { QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncInvoiceCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncInvoiceCompare, params); reg_lot (); reg_txn (); @@ -1423,5 +1421,5 @@ gboolean gncInvoiceRegister (void) gint64 gncInvoiceNextID (QofBook *book) { - return gnc_book_get_counter (book, _GNC_MOD_NAME); + return qof_book_get_counter (book, _GNC_MOD_NAME); } diff --git a/src/business/business-core/gncInvoice.h b/src/business/business-core/gncInvoice.h index 3341e6e72d..8aef82781e 100644 --- a/src/business/business-core/gncInvoice.h +++ b/src/business/business-core/gncInvoice.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncInvoice.h -- the Core Business Invoice Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncInvoice.h -- the Core Business Invoice Interface * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ @@ -15,7 +36,12 @@ typedef struct _gncInvoice GncInvoice; #include "gncOwner.h" #include "gnc-lot.h" -#define GNC_INVOICE_MODULE_NAME "gncInvoice" +#include "qofid.h" +#include "qofinstance.h" + +#define GNC_ID_INVOICE "gncInvoice" +#define GNC_IS_INVOICE(obj) (QOF_CHECK_TYPE((obj), GNC_ID_INVOICE)) +#define GNC_INVOICE(obj) (QOF_CHECK_CAST((obj), GNC_ID_INVOICE, GncInvoice)) /* Create/Destroy Functions */ @@ -45,8 +71,6 @@ void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry); /* Get Functions */ -QofBook * gncInvoiceGetBook (GncInvoice *invoice); -const GUID * gncInvoiceGetGUID (GncInvoice *invoice); const char * gncInvoiceGetID (GncInvoice *invoice); GncOwner * gncInvoiceGetOwner (GncInvoice *invoice); Timespec gncInvoiceGetDateOpened (GncInvoice *invoice); @@ -115,10 +139,15 @@ GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn); /* Given a LOT, find and return the Invoice attached to the lot */ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot); -GUID gncInvoiceRetGUID (GncInvoice *invoice); -GncInvoice * gncInvoiceLookupDirect (GUID guid, QofBook *book); +/** Return a pointer to the instance gncInvoice that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid); + */ +#define gncInvoiceLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_INVOICE, GncInvoice) -GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid); gboolean gncInvoiceIsDirty (GncInvoice *invoice); void gncInvoiceBeginEdit (GncInvoice *invoice); void gncInvoiceCommitEdit (GncInvoice *invoice); @@ -145,4 +174,10 @@ gboolean gncInvoiceIsPaid (GncInvoice *invoice); #define INVOICE_FROM_LOT "invoice-from-lot" #define INVOICE_FROM_TXN "invoice-from-txn" +/** deprecated functions */ +#define gncInvoiceGetBook(x) qof_instance_get_book(QOF_INSTANCE(x)) +#define gncInvoiceGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x)) +#define gncInvoiceRetGUID(x) (*(qof_instance_get_guid(QOF_INSTANCE(x)))) +#define gncInvoiceLookupDirect(G,B) gncInvoiceLookup((B),&(G)) + #endif /* GNC_INVOICE_H_ */ diff --git a/src/business/business-core/gncInvoiceP.h b/src/business/business-core/gncInvoiceP.h index 6de8fa2429..ce7369972b 100644 --- a/src/business/business-core/gncInvoiceP.h +++ b/src/business/business-core/gncInvoiceP.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncInvoiceP.h -- the Core Busines Invoice Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncInvoiceP.h -- the Core Busines Invoice Interface * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ @@ -11,14 +32,37 @@ #include "Account.h" #include "Transaction.h" #include "gnc-lot.h" +#include "qofid-p.h" gboolean gncInvoiceRegister (void); gint64 gncInvoiceNextID (QofBook *book); -void gncInvoiceSetGUID (GncInvoice *invoice, const GUID *guid); -void gncInvoiceSetDirty (GncInvoice *invoice, gboolean dirty); void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc); void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn); void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot); void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn); + +/** The gncCloneInvoice() routine makes a copy of the indicated + * invoice, placing it in the indicated book. It copies + * the name, description, type, due-days, discount, etc. + * It also copies (as needed) both parents and children, so that + * the parent-child relationship is correctly mirrored in the + * clone. + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ + +GncInvoice * gncCloneInvoice (GncInvoice *from, QofBook *); + +/** The gncInvoiceObtainTwin() will find the 'twin' of the + * indicated invoice in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneInvoice()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncInvoice * gncInvoiceObtainTwin (GncInvoice *from, QofBook *book); +#define gncInvoiceSetGUID(I,G) qof_entity_set_guid(QOF_ENTITY(I),(G)) #endif /* GNC_INVOICEP_H_ */ diff --git a/src/business/business-core/gncJob.c b/src/business/business-core/gncJob.c index 2a0ac7635a..abe48fca2c 100644 --- a/src/business/business-core/gncJob.c +++ b/src/business/business-core/gncJob.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncJob.c -- the Core Job Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncJob.c -- the Core Job Interface * Copyright (C) 2001, 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -13,53 +35,54 @@ #include "messages.h" #include "gnc-engine-util.h" #include "gnc-numeric.h" -#include "gnc-book.h" -#include "qofid.h" -#include "qofquerycore.h" -#include "qofquery.h" -#include "qofqueryobject.h" #include "gnc-event-p.h" #include "gnc-be-utils.h" + +#include "qofbook.h" +#include "qofclass.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofid.h" #include "qofid-p.h" +#include "qofobject.h" +#include "qofquery.h" +#include "qofquerycore.h" #include "gncBusiness.h" #include "gncJob.h" #include "gncJobP.h" +#include "gncOwnerP.h" -struct _gncJob { - QofBook * book; - GUID guid; - char * id; - char * name; - char * desc; - GncOwner owner; - gboolean active; - - int editlevel; - gboolean do_free; - gboolean dirty; +struct _gncJob +{ + QofInstance inst; + char * id; + char * name; + char * desc; + GncOwner owner; + gboolean active; }; -static short module = MOD_BUSINESS; +static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_JOB_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_JOB + +/* ================================================================== */ +/* misc inline functions */ #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 addObj (GncJob *job); -static void remObj (GncJob *job); - G_INLINE_FUNC void mark_job (GncJob *job); G_INLINE_FUNC void mark_job (GncJob *job) { - job->dirty = TRUE; - gncBusinessSetDirtyFlag (job->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + job->inst.dirty = TRUE; + qof_collection_mark_dirty (job->inst.entity.collection); + gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_MODIFY); } +/* ================================================================== */ /* Create/Destroy Functions */ GncJob *gncJobCreate (QofBook *book) @@ -69,26 +92,46 @@ GncJob *gncJobCreate (QofBook *book) if (!book) return NULL; job = g_new0 (GncJob, 1); - job->book = book; - job->dirty = FALSE; + qof_instance_init (&job->inst, _GNC_MOD_NAME, book); job->id = CACHE_INSERT (""); job->name = CACHE_INSERT (""); job->desc = CACHE_INSERT (""); job->active = TRUE; - qof_entity_guid_new (qof_book_get_entity_table (book), &job->guid); - addObj (job); + /* GncOwner not initialized */ + gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_CREATE); - gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + return job; +} +GncJob * +gncCloneJob (GncJob *from, QofBook *book) +{ + GncJob *job; + + if (!book) return NULL; + + job = g_new0 (GncJob, 1); + qof_instance_init (&job->inst, _GNC_MOD_NAME, book); + qof_instance_gemini (&job->inst, &from->inst); + + job->id = CACHE_INSERT (from->id); + job->name = CACHE_INSERT (from->name); + job->desc = CACHE_INSERT (from->desc); + job->active = from->active; + + job->owner = gncCloneOwner(&from->owner, book); + + gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_CREATE); + return job; } void gncJobDestroy (GncJob *job) { if (!job) return; - job->do_free = TRUE; + job->inst.do_free = TRUE; gncJobCommitEdit (job); } @@ -96,7 +139,7 @@ static void gncJobFree (GncJob *job) { if (!job) return; - gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (job->id); CACHE_REMOVE (job->name); @@ -113,22 +156,36 @@ static void gncJobFree (GncJob *job) break; } - remObj (job); - + qof_instance_release (&job->inst); g_free (job); } +GncJob * +gncJobObtainTwin (GncJob *from, QofBook *book) +{ + GncJob *job; + if (!from) return NULL; + + job = (GncJob *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!job) + { + job = gncCloneJob (from, book); + } + return job; +} + +/* ================================================================== */ /* Set Functions */ #define SET_STR(obj, member, str) { \ - char * tmp; \ - \ - if (!safe_strcmp (member, str)) return; \ - gncJobBeginEdit (obj); \ - tmp = CACHE_INSERT (str); \ - CACHE_REMOVE (member); \ - member = tmp; \ - } + char * tmp; \ + \ + if (!safe_strcmp (member, str)) return; \ + gncJobBeginEdit (obj); \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } void gncJobSetID (GncJob *job, const char *id) { @@ -157,24 +214,20 @@ void gncJobSetReference (GncJob *job, const char *desc) gncJobCommitEdit (job); } -void gncJobSetGUID (GncJob *job, const GUID *guid) -{ - if (!job || !guid) return; - if (guid_equal (guid, &job->guid)) return; - - gncJobBeginEdit (job); - remObj (job); - job->guid = *guid; - addObj (job); - gncJobCommitEdit (job); -} - void gncJobSetOwner (GncJob *job, GncOwner *owner) { if (!job) return; if (!owner) return; if (gncOwnerEqual (owner, &(job->owner))) return; - /* XXX: Fail if we have ANY orders or invoices */ + + switch (gncOwnerGetType (&(job->owner))) { + case GNC_OWNER_CUSTOMER: + case GNC_OWNER_VENDOR: + break; + default: + PERR("Unsupported Owner type"); + return; + } gncJobBeginEdit (job); @@ -218,34 +271,32 @@ void gncJobSetActive (GncJob *job, gboolean active) void gncJobBeginEdit (GncJob *job) { - GNC_BEGIN_EDIT (job, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&job->inst); } -static void gncJobOnError (GncJob *job, QofBackendError errcode) +static void gncJobOnError (QofInstance *inst, QofBackendError errcode) { PERR("Job QofBackend Failure: %d", errcode); } -static void gncJobOnDone (GncJob *job) +static inline void job_free (QofInstance *inst) { - job->dirty = FALSE; + GncJob *job = (GncJob *)inst; + gncJobFree (job); } +static inline void gncJobOnDone (QofInstance *qof) { } + void gncJobCommitEdit (GncJob *job) { - GNC_COMMIT_EDIT_PART1 (job); - GNC_COMMIT_EDIT_PART2 (job, _GNC_MOD_NAME, gncJobOnError, - gncJobOnDone, gncJobFree); + GNC_COMMIT_EDIT_PART1 (&job->inst); + GNC_COMMIT_EDIT_PART2 (&job->inst, gncJobOnError, + gncJobOnDone, job_free); } +/* ================================================================== */ /* Get Functions */ -QofBook * gncJobGetBook (GncJob *job) -{ - if (!job) return NULL; - return job->book; -} - const char * gncJobGetID (GncJob *job) { if (!job) return NULL; @@ -270,45 +321,12 @@ GncOwner * gncJobGetOwner (GncJob *job) return &(job->owner); } -const GUID * gncJobGetGUID (GncJob *job) -{ - if (!job) return NULL; - return &job->guid; -} - -GUID gncJobRetGUID (GncJob *job) -{ - const GUID *guid = gncJobGetGUID (job); - if (guid) - return *guid; - return *guid_null (); -} - gboolean gncJobGetActive (GncJob *job) { if (!job) return FALSE; return job->active; } -GncJob * gncJobLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} - -GncJob * gncJobLookupDirect (GUID guid, QofBook *book) -{ - if (!book) return NULL; - return gncJobLookup (book, &guid); -} - -gboolean gncJobIsDirty (GncJob *job) -{ - if (!job) return FALSE; - return job->dirty; -} - /* Other functions */ int gncJobCompare (const GncJob * a, const GncJob *b) { @@ -319,87 +337,50 @@ int gncJobCompare (const GncJob * a, const GncJob *b) { return (safe_strcmp(a->id, b->id)); } - +/* ================================================================== */ /* Package-Private functions */ -static void addObj (GncJob *job) -{ - gncBusinessAddObject (job->book, _GNC_MOD_NAME, job, &job->guid); -} - -static void remObj (GncJob *job) -{ - gncBusinessRemoveObject (job->book, _GNC_MOD_NAME, &job->guid); -} - -static void _gncJobCreate (QofBook *book) -{ - gncBusinessCreate (book, _GNC_MOD_NAME); -} - -static void _gncJobDestroy (QofBook *book) -{ - gncBusinessDestroy (book, _GNC_MOD_NAME); -} - -static gboolean _gncJobIsDirty (QofBook *book) -{ - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncJobMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncJobForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - static const char * _gncJobPrintable (gpointer item) { GncJob *c; - if (!item) return NULL; - c = item; return c->name; } -static QofObject gncJobDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Job", - _gncJobCreate, - _gncJobDestroy, - _gncJobIsDirty, - _gncJobMarkClean, - _gncJobForeach, - _gncJobPrintable +static QofObject gncJobDesc = +{ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Job", + book_begin: NULL, + book_end: NULL, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: _gncJobPrintable }; gboolean gncJobRegister (void) { - static QofQueryObject params[] = { - { JOB_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncJobGetID }, - { JOB_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncJobGetName }, - { JOB_REFERENCE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncJobGetReference }, - { JOB_OWNER, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncJobGetOwner }, - { JOB_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncJobGetActive }, - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncJobGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncJobGetGUID }, - { QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncJobGetActive }, + static QofParam params[] = { + { JOB_ID, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetID, NULL }, + { JOB_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetName, NULL }, + { JOB_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL }, + { JOB_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetReference, NULL }, + { JOB_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncJobGetOwner, NULL }, + { QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params); return qof_object_register (&gncJobDesc); } gint64 gncJobNextID (QofBook *book) { - return gnc_book_get_counter (book, _GNC_MOD_NAME); + return qof_book_get_counter (book, _GNC_MOD_NAME); } diff --git a/src/business/business-core/gncJob.h b/src/business/business-core/gncJob.h index 3b7fcce2c2..97d1da65b8 100644 --- a/src/business/business-core/gncJob.h +++ b/src/business/business-core/gncJob.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncJob.h -- the Core Job Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncJob.h -- the Core Job Interface * Copyright (C) 2001, 2002 Derek Atkins * Author: Derek Atkins */ @@ -9,10 +30,14 @@ typedef struct _gncJob GncJob; +#include "qofid.h" +#include "qofinstance.h" #include "gncAddress.h" #include "gncOwner.h" -#define GNC_JOB_MODULE_NAME "gncJob" +#define GNC_ID_JOB "gncJob" +#define GNC_IS_JOB(obj) (QOF_CHECK_TYPE((obj), GNC_ID_JOB)) +#define GNC_JOB(obj) (QOF_CHECK_CAST((obj), GNC_ID_JOB, GncJob)) /* Create/Destroy Functions */ @@ -32,20 +57,22 @@ void gncJobCommitEdit (GncJob *job); /* Get Functions */ -QofBook * gncJobGetBook (GncJob *job); -const GUID * gncJobGetGUID (GncJob *job); const char * gncJobGetID (GncJob *job); const char * gncJobGetName (GncJob *job); const char * gncJobGetReference (GncJob *job); GncOwner * gncJobGetOwner (GncJob *job); gboolean gncJobGetActive (GncJob *job); - -GUID gncJobRetGUID (GncJob *job); -GncJob *gncJobLookupDirect (GUID guid, QofBook *book); - -GncJob * gncJobLookup (QofBook *book, const GUID *guid); gboolean gncJobIsDirty (GncJob *job); +/** Return a pointer to the instance gncJob that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncJob * gncJobLookup (QofBook *book, const GUID *guid); + */ +#define gncJobLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_JOB, GncJob) + /* Other functions */ int gncJobCompare (const GncJob *a, const GncJob *b); @@ -56,4 +83,10 @@ int gncJobCompare (const GncJob *a, const GncJob *b); #define JOB_OWNER "owner" #define JOB_ACTIVE "active" +/** deprecated functions */ +#define gncJobGetBook(x) qof_instance_get_book(QOF_INSTANCE(x)) +#define gncJobGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x)) +#define gncJobRetGUID(x) (*(qof_instance_get_guid(QOF_INSTANCE(x)))) +#define gncJobLookupDirect(G,B) gncJobLookup((B),&(G)) + #endif /* GNC_JOB_H_ */ diff --git a/src/business/business-core/gncJobP.h b/src/business/business-core/gncJobP.h index 0fe7a5360f..96a620fb69 100644 --- a/src/business/business-core/gncJobP.h +++ b/src/business/business-core/gncJobP.h @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncJobP.h -- the Core Job Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncJobP.h -- the Core Job Interface * Copyright (C) 2001 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -8,9 +30,30 @@ #define GNC_JOBP_H_ #include "gncJob.h" +#include "qofid-p.h" gboolean gncJobRegister (void); gint64 gncJobNextID (QofBook *book); -void gncJobSetGUID (GncJob *job, const GUID *guid); + +/** The gncCloneTaxTable() routine makes a copy of the indicated + * tax table, placing it in the indicated book. It copies + * the id, name description and owner. + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ +GncJob * gncCloneJob (GncJob *from, QofBook *book); + +/** The gncJobObtainTwin() will find the 'twin' of the + * indicated job in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneJob()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncJob * gncJobObtainTwin (GncJob *from, QofBook *book); + +#define gncJobSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G)) #endif /* GNC_JOBP_H_ */ diff --git a/src/business/business-core/gncOrder.c b/src/business/business-core/gncOrder.c index 0b426f9923..eb1b0e7542 100644 --- a/src/business/business-core/gncOrder.c +++ b/src/business/business-core/gncOrder.c @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncOrder.c -- the Core Business Order * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOrder.c -- the Core Business Order * Copyright (C) 2001,2002 Derek Atkins * Author: Derek Atkins */ @@ -12,14 +33,19 @@ #include "gnc-numeric.h" #include "kvp_frame.h" #include "gnc-engine-util.h" -#include "gnc-book.h" + +#include "qofbook.h" +#include "qofclass.h" #include "qofid.h" -#include "qofquerycore.h" +#include "qofid-p.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" #include "qofquery.h" -#include "qofqueryobject.h" +#include "qofquerycore.h" + #include "gnc-event-p.h" #include "gnc-be-utils.h" -#include "qofid-p.h" #include "gncBusiness.h" #include "gncEntry.h" @@ -27,30 +53,27 @@ #include "gncOrder.h" #include "gncOrderP.h" #include "gncOwner.h" +#include "gncOwnerP.h" -struct _gncOrder { - QofBook *book; +struct _gncOrder +{ + QofInstance inst; - GUID guid; char * id; char * notes; + gboolean active; + char * reference; char * printname; GncOwner owner; GList * entries; Timespec opened; Timespec closed; - gboolean active; - - int editlevel; - gboolean do_free; - - gboolean dirty; }; static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_ORDER_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_ORDER #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)); @@ -65,19 +88,16 @@ static short module = MOD_BUSINESS; member = tmp; \ } -static void addObj (GncOrder *order); -static void remObj (GncOrder *order); - G_INLINE_FUNC void mark_order (GncOrder *order); G_INLINE_FUNC void mark_order (GncOrder *order) { - order->dirty = TRUE; - gncBusinessSetDirtyFlag (order->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&order->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + order->inst.dirty = TRUE; + qof_collection_mark_dirty (order->inst.entity.collection); + gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_MODIFY); } +/* =============================================================== */ /* Create/Destroy Functions */ GncOrder *gncOrderCreate (QofBook *book) @@ -87,7 +107,7 @@ GncOrder *gncOrderCreate (QofBook *book) if (!book) return NULL; order = g_new0 (GncOrder, 1); - order->book = book; + qof_instance_init (&order->inst, _GNC_MOD_NAME, book); order->id = CACHE_INSERT (""); order->notes = CACHE_INSERT (""); @@ -95,10 +115,7 @@ GncOrder *gncOrderCreate (QofBook *book) order->active = TRUE; - qof_entity_guid_new (qof_book_get_entity_table (book), &order->guid); - addObj (order); - - gnc_engine_generate_event (&order->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_CREATE); return order; } @@ -106,7 +123,7 @@ GncOrder *gncOrderCreate (QofBook *book) void gncOrderDestroy (GncOrder *order) { if (!order) return; - order->do_free = TRUE; + order->inst.do_free = TRUE; gncOrderCommitEdit (order); } @@ -114,33 +131,73 @@ static void gncOrderFree (GncOrder *order) { if (!order) return; - gnc_engine_generate_event (&order->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_DESTROY); g_list_free (order->entries); CACHE_REMOVE (order->id); CACHE_REMOVE (order->notes); CACHE_REMOVE (order->reference); - remObj (order); if (order->printname) g_free (order->printname); + qof_instance_release (&order->inst); g_free (order); } -/* Set Functions */ - -void gncOrderSetGUID (GncOrder *order, const GUID *guid) +GncOrder * +gncCloneOrder (GncOrder *from, QofBook *book) { - if (!order || !guid) return; - if (guid_equal (guid, &order->guid)) return; + GList *node; + GncOrder *order; - gncOrderBeginEdit (order); - remObj (order); - order->guid = *guid; - addObj (order); - gncOrderCommitEdit (order); + if (!book) return NULL; + + order = g_new0 (GncOrder, 1); + qof_instance_init (&order->inst, _GNC_MOD_NAME, book); + qof_instance_gemini (&order->inst, &from->inst); + + order->id = CACHE_INSERT (from->id); + order->notes = CACHE_INSERT (from->notes); + order->reference = CACHE_INSERT (from->reference); + + order->active = from->active; + order->printname = NULL; /* yes, null, that's right */ + order->opened = from->opened; + order->closed = from->closed; + + order->owner = gncCloneOwner (&from->owner, book); + + order->entries = NULL; + for (node = g_list_last(from->entries); node; node=node->prev) + { + GncEntry *entry = node->data; + entry = gncEntryObtainTwin (entry, book); + order->entries = g_list_prepend (order->entries, entry); + } + + gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_CREATE); + + return order; } +GncOrder * +gncOrderObtainTwin (GncOrder *from, QofBook *book) +{ + GncOrder *order; + if (!book) return NULL; + + order = (GncOrder *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!order) + { + order = gncCloneOrder (from, book); + } + + return order; +} + +/* =============================================================== */ +/* Set Functions */ + void gncOrderSetID (GncOrder *order, const char *id) { if (!order || !id) return; @@ -206,12 +263,7 @@ void gncOrderSetActive (GncOrder *order, gboolean active) gncOrderCommitEdit (order); } -void gncOrderSetDirty (GncOrder *order, gboolean dirty) -{ - if (!order) return; - order->dirty = dirty; -} - +/* =============================================================== */ /* Add an Entry to the Order */ void gncOrderAddEntry (GncOrder *order, GncEntry *entry) { @@ -242,18 +294,6 @@ void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry) /* Get Functions */ -QofBook * gncOrderGetBook (GncOrder *order) -{ - if (!order) return NULL; - return order->book; -} - -const GUID * gncOrderGetGUID (GncOrder *order) -{ - if (!order) return NULL; - return &(order->guid); -} - const char * gncOrderGetID (GncOrder *order) { if (!order) return NULL; @@ -305,19 +345,6 @@ GList * gncOrderGetEntries (GncOrder *order) return order->entries; } -GncOrder * gncOrderLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} - -gboolean gncOrderIsDirty (GncOrder *order) -{ - if (!order) return FALSE; - return order->dirty; -} - gboolean gncOrderIsClosed (GncOrder *order) { if (!order) return FALSE; @@ -325,26 +352,31 @@ gboolean gncOrderIsClosed (GncOrder *order) return FALSE; } +/* =============================================================== */ + void gncOrderBeginEdit (GncOrder *order) { - GNC_BEGIN_EDIT (order, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&order->inst); } -static void gncOrderOnError (GncOrder *order, QofBackendError errcode) +static inline void gncOrderOnError (QofInstance *order, QofBackendError errcode) { PERR("Order QofBackend Failure: %d", errcode); } -static void gncOrderOnDone (GncOrder *order) +static inline void gncOrderOnDone (QofInstance *order) {} + +static inline void order_free (QofInstance *inst) { - order->dirty = FALSE; + GncOrder *order = (GncOrder *) inst; + gncOrderFree (order); } void gncOrderCommitEdit (GncOrder *order) { - GNC_COMMIT_EDIT_PART1 (order); - GNC_COMMIT_EDIT_PART2 (order, _GNC_MOD_NAME, gncOrderOnError, - gncOrderOnDone, gncOrderFree); + GNC_COMMIT_EDIT_PART1 (&order->inst); + GNC_COMMIT_EDIT_PART2 (&order->inst, gncOrderOnError, + gncOrderOnDone, order_free); } int gncOrderCompare (GncOrder *a, GncOrder *b) @@ -364,54 +396,20 @@ int gncOrderCompare (GncOrder *a, GncOrder *b) compare = timespec_cmp (&(a->closed), &(b->closed)); if (compare) return compare; - return guid_compare (&(a->guid), &(b->guid)); + return guid_compare (&(a->inst.entity.guid), &(b->inst.entity.guid)); } +/* =========================================================== */ /* Package-Private functions */ -static void addObj (GncOrder *order) -{ - gncBusinessAddObject (order->book, _GNC_MOD_NAME, order, &order->guid); -} - -static void remObj (GncOrder *order) -{ - gncBusinessRemoveObject (order->book, _GNC_MOD_NAME, &order->guid); -} - -static void _gncOrderCreate (QofBook *book) -{ - gncBusinessCreate (book, _GNC_MOD_NAME); -} - -static void _gncOrderDestroy (QofBook *book) -{ - gncBusinessDestroy (book, _GNC_MOD_NAME); -} - -static gboolean _gncOrderIsDirty (QofBook *book) -{ - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncOrderMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncOrderForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - -static const char * _gncOrderPrintable (gpointer obj) +static const char * +_gncOrderPrintable (gpointer obj) { GncOrder *order = obj; g_return_val_if_fail (order, NULL); - if (order->dirty || order->printname == NULL) { + if (order->inst.dirty || order->printname == NULL) { if (order->printname) g_free (order->printname); order->printname = @@ -422,40 +420,41 @@ static const char * _gncOrderPrintable (gpointer obj) return order->printname; } -static QofObject gncOrderDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Order", - _gncOrderCreate, - _gncOrderDestroy, - _gncOrderIsDirty, - _gncOrderMarkClean, - _gncOrderForeach, - _gncOrderPrintable, +static QofObject gncOrderDesc = +{ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Order", + book_begin: NULL, + book_end: NULL, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: _gncOrderPrintable, }; gboolean gncOrderRegister (void) { - static QofQueryObject params[] = { - { ORDER_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncOrderGetID }, - { ORDER_REFERENCE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncOrderGetReference }, - { ORDER_OWNER, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncOrderGetOwner }, - { ORDER_OPENED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncOrderGetDateOpened }, - { ORDER_IS_CLOSED, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncOrderIsClosed }, - { ORDER_CLOSED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncOrderGetDateClosed }, - { ORDER_NOTES, QOF_QUERYCORE_STRING, (QofAccessFunc)gncOrderGetNotes }, - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncOrderGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncOrderGetGUID }, - { QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncOrderGetActive }, + static QofParam params[] = { + { ORDER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetID, NULL }, + { ORDER_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetReference, NULL }, + { ORDER_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncOrderGetOwner, NULL }, + { ORDER_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateOpened, NULL }, + { ORDER_IS_CLOSED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderIsClosed, NULL }, + { ORDER_CLOSED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateClosed, NULL }, + { ORDER_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetNotes, NULL }, + { QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderGetActive, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncOrderCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncOrderCompare, params); return qof_object_register (&gncOrderDesc); } gint64 gncOrderNextID (QofBook *book) { - return gnc_book_get_counter (book, _GNC_MOD_NAME); + return qof_book_get_counter (book, _GNC_MOD_NAME); } diff --git a/src/business/business-core/gncOrder.h b/src/business/business-core/gncOrder.h index d5460a223f..902b29dfea 100644 --- a/src/business/business-core/gncOrder.h +++ b/src/business/business-core/gncOrder.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncOrder.h -- the Core Business Order Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOrder.h -- the Core Business Order Interface * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ @@ -9,11 +30,15 @@ typedef struct _gncOrder GncOrder; -#include "gnc-book.h" #include "gncEntry.h" #include "gncOwner.h" +#include "qofbook.h" +#include "qofid.h" +#include "qofinstance.h" -#define GNC_ORDER_MODULE_NAME "gncOrder" +#define GNC_ID_ORDER "gncOrder" +#define GNC_IS_ORDER(obj) (QOF_CHECK_TYPE((obj), GNC_ID_ORDER)) +#define GNC_ORDER(obj) (QOF_CHECK_CAST((obj), GNC_ID_ORDER, GncOrder)) /* Create/Destroy Functions */ @@ -36,8 +61,6 @@ void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry); /* Get Functions */ -QofBook * gncOrderGetBook (GncOrder *order); -const GUID * gncOrderGetGUID (GncOrder *order); const char * gncOrderGetID (GncOrder *order); GncOwner * gncOrderGetOwner (GncOrder *order); Timespec gncOrderGetDateOpened (GncOrder *order); @@ -49,7 +72,6 @@ gboolean gncOrderGetActive (GncOrder *order); /* Get the list Entries */ GList * gncOrderGetEntries (GncOrder *order); -GncOrder * gncOrderLookup (QofBook *book, const GUID *guid); gboolean gncOrderIsDirty (GncOrder *order); void gncOrderBeginEdit (GncOrder *order); void gncOrderCommitEdit (GncOrder *order); @@ -57,6 +79,15 @@ int gncOrderCompare (GncOrder *a, GncOrder *b); gboolean gncOrderIsClosed (GncOrder *order); +/** Return a pointer to the instance gncOrder that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncOrder * gncOrderLookup (QofBook *book, const GUID *guid); + */ +#define gncOrderLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_ORDER, GncOrder) + #define ORDER_ID "id" #define ORDER_REFERENCE "reference" #define ORDER_OWNER "owner" @@ -65,4 +96,8 @@ gboolean gncOrderIsClosed (GncOrder *order); #define ORDER_IS_CLOSED "is_closed?" #define ORDER_NOTES "notes" +/** deprecated functions */ +#define gncOrderGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x)) +#define gncOrderGetBook(x) qof_instance_get_book(QOF_INSTANCE(x)) + #endif /* GNC_ORDER_H_ */ diff --git a/src/business/business-core/gncOrderP.h b/src/business/business-core/gncOrderP.h index 209cf554a7..5554151e0c 100644 --- a/src/business/business-core/gncOrderP.h +++ b/src/business/business-core/gncOrderP.h @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncOrderP.h -- the Core Busines Order Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOrderP.h -- the Core Busines Order Interface * Copyright (C) 2001 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -8,10 +30,31 @@ #define GNC_ORDERP_H_ #include "gncOrder.h" +#include "qofid-p.h" gboolean gncOrderRegister (void); gint64 gncOrderNextID (QofBook *book); -void gncOrderSetGUID (GncOrder *order, const GUID *guid); -void gncOrderSetDirty (GncOrder *order, gboolean dirty); + +/** The gncCloneOrder() routine makes a copy of the indicated + * order, placing it in the indicated book. It copies + * the id, notes, reference, etc. + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ + +GncOrder * gncCloneOrder (GncOrder *from, QofBook *); + +/** The gncOrderObtainTwin() will find the 'twin' of the + * indicated order in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneOrder()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncOrder * gncOrderObtainTwin (GncOrder *from, QofBook *book); + +#define gncOrderSetGUID(O,G) qof_entity_set_guid(QOF_ENTITY(O),(G)) #endif /* GNC_ORDERP_H_ */ diff --git a/src/business/business-core/gncOwner.c b/src/business/business-core/gncOwner.c index bbb7ec672e..1a09f91437 100644 --- a/src/business/business-core/gncOwner.c +++ b/src/business/business-core/gncOwner.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncOwner.c -- Business Interface: Object OWNERs * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOwner.c -- Business Interface: Object OWNERs * Copyright (C) 2001, 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -9,14 +31,19 @@ #include #include /* for memcpy() */ +#include "qofbook.h" +#include "qofclass.h" #include "qofquerycore.h" #include "qofquery.h" -#include "qofqueryobject.h" +#include "gncCustomerP.h" +#include "gncEmployeeP.h" +#include "gncJobP.h" #include "gncOwner.h" #include "gncOwnerP.h" +#include "gncVendorP.h" -#define _GNC_MOD_NAME GNC_OWNER_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_OWNER #define GNC_OWNER_ID "gncOwner" #define GNC_OWNER_TYPE "owner-type" @@ -137,6 +164,36 @@ void gncOwnerCopy (const GncOwner *src, GncOwner *dest) memcpy (dest, src, sizeof (*dest)); } +GncOwner +gncCloneOwner (const GncOwner *from, QofBook *book) +{ + GncOwner owner = { GNC_OWNER_NONE }; + if (!from) return owner; + owner.type = from->type; + switch (from->type) + { + case GNC_OWNER_NONE: + return owner; + case GNC_OWNER_UNDEFINED: + owner.owner.undefined = from->owner.undefined; /* XXX probably wrong ! */ + return owner; + case GNC_OWNER_CUSTOMER: + owner.owner.customer = gncCustomerObtainTwin (from->owner.customer, book); + return owner; + case GNC_OWNER_JOB: + owner.owner.job = gncJobObtainTwin (from->owner.job, book); + return owner; + case GNC_OWNER_VENDOR: + owner.owner.vendor = gncVendorObtainTwin (from->owner.vendor, book); + return owner; + case GNC_OWNER_EMPLOYEE: + owner.owner.employee = gncEmployeeObtainTwin (from->owner.employee, book); + return owner; + default: + return owner; + } +} + gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b) { if (!a || !b) return FALSE; @@ -173,13 +230,13 @@ const GUID * gncOwnerGetGUID (GncOwner *owner) default: return NULL; case GNC_OWNER_CUSTOMER: - return gncCustomerGetGUID (owner->owner.customer); + return qof_instance_get_guid (QOF_INSTANCE(owner->owner.customer)); case GNC_OWNER_JOB: - return gncJobGetGUID (owner->owner.job); + return qof_instance_get_guid (QOF_INSTANCE(owner->owner.job)); case GNC_OWNER_VENDOR: - return gncVendorGetGUID (owner->owner.vendor); + return qof_instance_get_guid (QOF_INSTANCE(owner->owner.vendor)); case GNC_OWNER_EMPLOYEE: - return gncEmployeeGetGUID (owner->owner.employee); + return qof_instance_get_guid (QOF_INSTANCE(owner->owner.employee)); } } @@ -329,31 +386,31 @@ owner_from_lot (GNCLot *lot) static void reg_lot (void) { - static QofQueryObject params[] = { - { OWNER_FROM_LOT, _GNC_MOD_NAME, (QofAccessFunc)owner_from_lot }, + static QofParam params[] = { + { OWNER_FROM_LOT, _GNC_MOD_NAME, (QofAccessFunc)owner_from_lot, NULL }, { NULL }, }; - qof_query_object_register (GNC_ID_LOT, NULL, params); + qof_class_register (GNC_ID_LOT, NULL, params); } gboolean gncOwnerRegister (void) { - static QofQueryObject params[] = { - { OWNER_TYPE, QOF_QUERYCORE_INT64, (QofAccessFunc)gncOwnerGetType }, - { OWNER_CUSTOMER, GNC_CUSTOMER_MODULE_NAME, - (QofAccessFunc)gncOwnerGetCustomer }, - { OWNER_JOB, GNC_JOB_MODULE_NAME, (QofAccessFunc)gncOwnerGetJob }, - { OWNER_VENDOR, GNC_VENDOR_MODULE_NAME, (QofAccessFunc)gncOwnerGetVendor }, - { OWNER_EMPLOYEE, GNC_EMPLOYEE_MODULE_NAME, (QofAccessFunc)gncOwnerGetEmployee }, - { OWNER_PARENT, _GNC_MOD_NAME, (QofAccessFunc)gncOwnerGetEndOwner }, - { OWNER_PARENTG, QOF_QUERYCORE_GUID, (QofAccessFunc)gncOwnerGetEndGUID }, - { OWNER_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncOwnerGetName }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncOwnerGetGUID }, + static QofParam params[] = { + { OWNER_TYPE, QOF_TYPE_INT64, (QofAccessFunc)gncOwnerGetType, NULL }, + { OWNER_CUSTOMER, GNC_ID_CUSTOMER, + (QofAccessFunc)gncOwnerGetCustomer, NULL }, + { OWNER_JOB, GNC_ID_JOB, (QofAccessFunc)gncOwnerGetJob, NULL }, + { OWNER_VENDOR, GNC_ID_VENDOR, (QofAccessFunc)gncOwnerGetVendor, NULL }, + { OWNER_EMPLOYEE, GNC_ID_EMPLOYEE, (QofAccessFunc)gncOwnerGetEmployee, NULL }, + { OWNER_PARENT, GNC_ID_OWNER, (QofAccessFunc)gncOwnerGetEndOwner, NULL }, + { OWNER_PARENTG, QOF_TYPE_GUID, (QofAccessFunc)gncOwnerGetEndGUID, NULL }, + { OWNER_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncOwnerGetName, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)gncOwnerGetGUID, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncOwnerCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncOwnerCompare, params); reg_lot (); return TRUE; diff --git a/src/business/business-core/gncOwner.h b/src/business/business-core/gncOwner.h index baa3d5870f..dfb6a5df6f 100644 --- a/src/business/business-core/gncOwner.h +++ b/src/business/business-core/gncOwner.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncOwner.h -- Business Interface: Object OWNERs * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOwner.h -- Business Interface: Object OWNERs * Copyright (C) 2001, 2002 Derek Atkins * Author: Derek Atkins */ @@ -9,7 +30,7 @@ typedef struct gnc_owner_s GncOwner; -#define GNC_OWNER_MODULE_NAME "gncOwner" +#define GNC_ID_OWNER "gncOwner" #include "gncCustomer.h" #include "gncJob.h" @@ -27,13 +48,13 @@ typedef enum { } GncOwnerType; struct gnc_owner_s { - GncOwnerType type; + GncOwnerType type; union { - gpointer undefined; - GncCustomer * customer; - GncJob * job; - GncVendor * vendor; - GncEmployee * employee; + gpointer undefined; + GncCustomer * customer; + GncJob * job; + GncVendor * vendor; + GncEmployee * employee; } owner; }; @@ -78,16 +99,16 @@ void gncOwnerAttachToLot (GncOwner *owner, GNCLot *lot); */ gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner); -#define OWNER_TYPE "type" -#define OWNER_CUSTOMER "customer" -#define OWNER_JOB "job" -#define OWNER_VENDOR "vendor" -#define OWNER_EMPLOYEE "employee" -#define OWNER_PARENT "parent" -#define OWNER_PARENTG "parent-guid" -#define OWNER_NAME "name" +#define OWNER_TYPE "type" +#define OWNER_CUSTOMER "customer" +#define OWNER_JOB "job" +#define OWNER_VENDOR "vendor" +#define OWNER_EMPLOYEE "employee" +#define OWNER_PARENT "parent" +#define OWNER_PARENTG "parent-guid" +#define OWNER_NAME "name" -#define OWNER_FROM_LOT "owner-from-lot" +#define OWNER_FROM_LOT "owner-from-lot" /* * These two functions are mainly for the convenience of scheme code. diff --git a/src/business/business-core/gncOwnerP.h b/src/business/business-core/gncOwnerP.h index c6a352687d..b4ab34ef65 100644 --- a/src/business/business-core/gncOwnerP.h +++ b/src/business/business-core/gncOwnerP.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncOwnerP.h -- Business Interface: Object OWNERs private file * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOwnerP.h -- Business Interface: Object OWNERs * Copyright (C) 2001, 2002 Derek Atkins * Author: Derek Atkins */ @@ -7,6 +28,14 @@ #ifndef GNC_OWNERP_H_ #define GNC_OWNERP_H_ +#include "qofbook.h" +#include "gncOwner.h" + gboolean gncOwnerRegister (void); +/** The gncCloneOwner() routine makes a copy of the indicated + * owner union structure. + */ +GncOwner gncCloneOwner (const GncOwner *from, QofBook *); + #endif /* GNC_OWNERP_H_ */ diff --git a/src/business/business-core/gncTaxTable.c b/src/business/business-core/gncTaxTable.c index 549fd3ca7a..4854314908 100644 --- a/src/business/business-core/gncTaxTable.c +++ b/src/business/business-core/gncTaxTable.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncTaxTable.c -- the Gnucash Tax Table interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncTaxTable.c -- the Gnucash Tax Table interface * Copyright (C) 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -11,52 +33,57 @@ #include "messages.h" #include "gnc-numeric.h" #include "gnc-engine-util.h" -#include "gnc-book.h" -#include "qofid.h" -#include "qofquerycore.h" -#include "qofquery.h" -#include "qofqueryobject.h" #include "gnc-event-p.h" #include "gnc-be-utils.h" + +#include "qofbook.h" +#include "qofclass.h" +#include "qofid.h" #include "qofid-p.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" +#include "qofquery.h" +#include "qofquerycore.h" #include "gncBusiness.h" #include "gncTaxTableP.h" -struct _gncTaxTable { - GUID guid; - char * name; - GList * entries; +struct _gncTaxTable +{ + QofInstance inst; + char * name; + GList * entries; + Timespec modtime; /* internal date of last modtime */ - Timespec modtime; /* internal date of last modtime */ - gint64 refcount; - QofBook * book; - GncTaxTable * parent; /* if non-null, we are an immutable child */ - GncTaxTable * child; /* if non-null, we have not changed */ - gboolean invisible; - - GList * children; /* A list of children */ - - int editlevel; - gboolean do_free; - gboolean dirty; + /* See src/doc/business.txt for an explanation of the following */ + /* Code that handles this is *identical* to that in gncBillTerm */ + gint64 refcount; + GncTaxTable * parent; /* if non-null, we are an immutable child */ + GncTaxTable * child; /* if non-null, we have not changed */ + gboolean invisible; + GList * children; /* list of children for disconnection */ }; -struct _gncTaxTableEntry { - GncTaxTable * table; - Account * account; - GncAmountType type; - gnc_numeric amount; +struct _gncTaxTableEntry +{ + GncTaxTable * table; + Account * account; + GncAmountType type; + gnc_numeric amount; }; -struct _book_info { - GncBookInfo bi; - GList * tables; /* visible tables */ +struct _book_info +{ + GList * tables; /* visible tables */ }; -static short module = MOD_BUSINESS; +static GncTaxTableEntry * CloneTaxEntry (GncTaxTableEntry*, QofBook *); +static short module = MOD_BUSINESS; + +/* =============================================================== */ /* You must edit the functions in this block in tandem. KEEP THEM IN SYNC! */ @@ -116,76 +143,186 @@ gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type) } #undef GNC_RETURN_ON_MATCH -#define _GNC_MOD_NAME GNC_TAXTABLE_MODULE_NAME +/* =============================================================== */ +/* Misc inline functions */ + +#define _GNC_MOD_NAME GNC_ID_TAXTABLE #define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str)); #define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str)); #define SET_STR(obj, member, str) { \ - char * tmp; \ - \ - if (!safe_strcmp (member, str)) return; \ - gncTaxTableBeginEdit (obj); \ - tmp = CACHE_INSERT (str); \ - CACHE_REMOVE (member); \ - member = tmp; \ - } + char * tmp; \ + \ + if (!safe_strcmp (member, str)) return; \ + gncTaxTableBeginEdit (obj); \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } -static void add_or_rem_object (GncTaxTable *table, gboolean add); -static void addObj (GncTaxTable *table); -static void remObj (GncTaxTable *table); -static void maybe_resort_list (GncTaxTable *table); - -static void gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child); - -G_INLINE_FUNC void mark_table (GncTaxTable *table); -G_INLINE_FUNC void +static inline void mark_table (GncTaxTable *table) { - table->dirty = TRUE; - gncBusinessSetDirtyFlag (table->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&table->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + table->inst.dirty = TRUE; + qof_collection_mark_dirty (table->inst.entity.collection); + gnc_engine_gen_event (&table->inst.entity, GNC_EVENT_MODIFY); } -G_INLINE_FUNC void mod_table (GncTaxTable *table); -G_INLINE_FUNC void +static inline void +maybe_resort_list (GncTaxTable *table) +{ + struct _book_info *bi; + + if (table->parent || table->invisible) return; + bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare); +} + +static inline void mod_table (GncTaxTable *table) { timespecFromTime_t (&table->modtime, time(NULL)); } +static inline void addObj (GncTaxTable *table) +{ + struct _book_info *bi; + bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi->tables = g_list_insert_sorted (bi->tables, table, + (GCompareFunc)gncTaxTableCompare); +} + +static inline void remObj (GncTaxTable *table) +{ + struct _book_info *bi; + bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi->tables = g_list_remove (bi->tables, table); +} + +static inline void +gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child) +{ + g_return_if_fail(table); + g_return_if_fail(child); + g_return_if_fail(table->inst.do_free == FALSE); + + table->children = g_list_prepend(table->children, child); +} + +static inline void +gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child) +{ + g_return_if_fail(table); + g_return_if_fail(child); + + if (table->inst.do_free) return; + + table->children = g_list_remove(table->children, child); +} + +/* =============================================================== */ /* Create/Destroy Functions */ -GncTaxTable * gncTaxTableCreate (QofBook *book) + +GncTaxTable * +gncTaxTableCreate (QofBook *book) { GncTaxTable *table; if (!book) return NULL; table = g_new0 (GncTaxTable, 1); - table->book = book; + qof_instance_init (&table->inst, _GNC_MOD_NAME, book); table->name = CACHE_INSERT (""); - qof_entity_guid_new (qof_book_get_entity_table (book), &table->guid); addObj (table); - gnc_engine_generate_event (&table->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&table->inst.entity, GNC_EVENT_CREATE); return table; } -void gncTaxTableDestroy (GncTaxTable *table) + +GncTaxTable * +gncCloneTaxTable (GncTaxTable *from, QofBook *book) +{ + GList *node; + GncTaxTable *table; + if (!book) return NULL; + + table = g_new0 (GncTaxTable, 1); + qof_instance_init (&table->inst, _GNC_MOD_NAME, book); + qof_instance_gemini (&table->inst, &from->inst); + + table->name = CACHE_INSERT (from->name); + table->modtime = from->modtime; + table->invisible = from->invisible; + + table->refcount = 0; + + /* Make copies of parents and children. Note that this can be + * a recursive copy ... treat as doubly-linked list. */ + if (from->child) + { + table->child = gncTaxTableObtainTwin (from->child, book); + table->child->parent = table; + } + if (from->parent) + { + table->parent = gncTaxTableObtainTwin (from->parent, book); + table->parent->child = table; + } + for (node=g_list_last(from->children); node; node=node->next) + { + GncTaxTable *tbl = node->data; + tbl = gncTaxTableObtainTwin (tbl, book); + tbl->parent = table; + table->children = g_list_prepend(table->children, tbl); + } + + /* Copy tax entries, preserving the order in the list */ + table->entries = NULL; + for (node=g_list_last(from->entries); node; node=node->prev) + { + GncTaxTableEntry *ent = node->data; + ent = CloneTaxEntry (ent, book); + table->entries = g_list_prepend (table->entries, ent); + } + + addObj (table); + gnc_engine_gen_event (&table->inst.entity, GNC_EVENT_CREATE); + return table; +} + +GncTaxTable * +gncTaxTableObtainTwin (GncTaxTable *from, QofBook *book) +{ + GncTaxTable *table; + if (!from) return NULL; + + table = (GncTaxTable *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!table) + { + table = gncCloneTaxTable (table, book); + } + return table; +} + + +void +gncTaxTableDestroy (GncTaxTable *table) { if (!table) return; - table->do_free = TRUE; - gncBusinessSetDirtyFlag (table->book, _GNC_MOD_NAME, TRUE); + table->inst.do_free = TRUE; + qof_collection_mark_dirty (table->inst.entity.collection); gncTaxTableCommitEdit (table); } -static void gncTaxTableFree (GncTaxTable *table) +static void +gncTaxTableFree (GncTaxTable *table) { GList *list; GncTaxTable *child; if (!table) return; - gnc_engine_generate_event (&table->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&table->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (table->name); remObj (table); @@ -194,7 +331,7 @@ static void gncTaxTableFree (GncTaxTable *table) gncTaxTableEntryDestroy (list->data); g_list_free (table->entries); - if (!table->do_free) + if (!table->inst.do_free) PERR("free a taxtable without do_free set!"); /* disconnect from parent */ @@ -208,30 +345,11 @@ static void gncTaxTableFree (GncTaxTable *table) } g_list_free(table->children); + qof_instance_release (&table->inst); g_free (table); } -static void -gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child) -{ - g_return_if_fail(table); - g_return_if_fail(child); - g_return_if_fail(table->do_free == FALSE); - - table->children = g_list_prepend(table->children, child); -} - -static void -gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child) -{ - g_return_if_fail(table); - g_return_if_fail(child); - - if (table->do_free) - return; - - table->children = g_list_remove(table->children, child); -} +/* =============================================================== */ GncTaxTableEntry * gncTaxTableEntryCreate (void) { @@ -247,20 +365,28 @@ void gncTaxTableEntryDestroy (GncTaxTableEntry *entry) g_free (entry); } - -/* Set Functions */ -void gncTaxTableSetGUID (GncTaxTable *table, const GUID *guid) +/** Makes a clone. The account is from the appriate book. + * Note that the table is left blank (for performance reasons + * we set it above, when cloning the table). + */ +static GncTaxTableEntry * +CloneTaxEntry (GncTaxTableEntry*from, QofBook *book) { - if (!table || !guid) return; - if (guid_equal (guid, &table->guid)) return; + QofInstance *acc; + GncTaxTableEntry *entry; + entry = g_new0 (GncTaxTableEntry, 1); - gncTaxTableBeginEdit (table); - remObj (table); - table->guid = *guid; - addObj (table); - gncTaxTableCommitEdit (table); + entry->type = from->type; + entry->amount = from->amount; + + acc = qof_instance_lookup_twin (QOF_INSTANCE(from->account), book); + entry->account = (Account *) acc; + return entry; } +/* =============================================================== */ +/* Set Functions */ + void gncTaxTableSetName (GncTaxTable *table, const char *name) { if (!table || !name) return; @@ -295,7 +421,7 @@ void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child) void gncTaxTableIncRef (GncTaxTable *table) { if (!table) return; - if (table->parent || table->invisible) return; /* children dont need refcounts */ + if (table->parent || table->invisible) return; /* children dont need refcounts */ gncTaxTableBeginEdit (table); table->refcount++; gncTaxTableCommitEdit (table); @@ -304,7 +430,7 @@ void gncTaxTableIncRef (GncTaxTable *table) void gncTaxTableDecRef (GncTaxTable *table) { if (!table) return; - if (table->parent || table->invisible) return; /* children dont need refcounts */ + if (table->parent || table->invisible) return; /* children dont need refcounts */ gncTaxTableBeginEdit (table); table->refcount--; g_return_if_fail (table->refcount >= 0); @@ -319,10 +445,12 @@ void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount) void gncTaxTableMakeInvisible (GncTaxTable *table) { + struct _book_info *bi; if (!table) return; gncTaxTableBeginEdit (table); table->invisible = TRUE; - add_or_rem_object (table, FALSE); + bi = qof_book_get_data (table->inst.book, _GNC_MOD_NAME); + bi->tables = g_list_remove (bi->tables, table); gncTaxTableCommitEdit (table); } @@ -370,7 +498,7 @@ void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry) entry->table = table; table->entries = g_list_insert_sorted (table->entries, entry, - (GCompareFunc)gncTaxTableEntryCompare); + (GCompareFunc)gncTaxTableEntryCompare); mark_table (table); mod_table (table); gncTaxTableCommitEdit (table); @@ -395,36 +523,36 @@ void gncTaxTableChanged (GncTaxTable *table) gncTaxTableCommitEdit (table); } +/* =============================================================== */ + void gncTaxTableBeginEdit (GncTaxTable *table) { - GNC_BEGIN_EDIT (table, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&table->inst); } -static void gncTaxTableOnError (GncTaxTable *table, QofBackendError errcode) +static inline void gncTaxTableOnError (QofInstance *inst, QofBackendError errcode) { PERR("TaxTable QofBackend Failure: %d", errcode); } -static void gncTaxTableOnDone (GncTaxTable *table) +static inline void gncTaxTableOnDone (QofInstance *inst) {} + +static inline void table_free (QofInstance *inst) { - table->dirty = FALSE; + GncTaxTable *table = (GncTaxTable *) inst; + gncTaxTableFree (table); } void gncTaxTableCommitEdit (GncTaxTable *table) { - GNC_COMMIT_EDIT_PART1 (table); - GNC_COMMIT_EDIT_PART2 (table, _GNC_MOD_NAME, gncTaxTableOnError, - gncTaxTableOnDone, gncTaxTableFree); + GNC_COMMIT_EDIT_PART1 (&table->inst); + GNC_COMMIT_EDIT_PART2 (&table->inst, gncTaxTableOnError, + gncTaxTableOnDone, table_free); } +/* =============================================================== */ /* Get Functions */ -GncTaxTable * gncTaxTableLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name) { @@ -443,23 +571,10 @@ GList * gncTaxTableGetTables (QofBook *book) struct _book_info *bi; if (!book) return NULL; - bi = gnc_book_get_data (book, _GNC_MOD_NAME); + bi = qof_book_get_data (book, _GNC_MOD_NAME); return bi->tables; } - -const GUID *gncTaxTableGetGUID (GncTaxTable *table) -{ - if (!table) return NULL; - return &table->guid; -} - -QofBook *gncTaxTableGetBook (GncTaxTable *table) -{ - if (!table) return NULL; - return table->book; -} - const char *gncTaxTableGetName (GncTaxTable *table) { if (!table) return NULL; @@ -485,7 +600,7 @@ static GncTaxTable *gncTaxTableCopy (GncTaxTable *table) GList *list; if (!table) return NULL; - t = gncTaxTableCreate (table->book); + t = gncTaxTableCreate (table->inst.book); gncTaxTableSetName (t, table->name); for (list = table->entries; list; list=list->next) { GncTaxTableEntry *entry, *e; @@ -608,7 +723,7 @@ GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value) res = li->data; if (res->account == acc) { res->value = gnc_numeric_add (res->value, value, GNC_DENOM_AUTO, - GNC_DENOM_LCD); + GNC_DENOM_LCD); return list; } } @@ -655,57 +770,8 @@ void gncAccountValueDestroy (GList *list) g_list_free (list); } -GUID gncTaxTableRetGUID (GncTaxTable *table) -{ - if (!table) - return *guid_null(); - - return table->guid; -} - -GncTaxTable *gncTaxTableLookupDirect (GUID guid, QofBook *book) -{ - if (!book) return NULL; - return gncTaxTableLookup (book, &guid); -} - /* Package-Private functions */ -static void maybe_resort_list (GncTaxTable *table) -{ - struct _book_info *bi; - - if (table->parent || table->invisible) return; - bi = gnc_book_get_data (table->book, _GNC_MOD_NAME); - bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare); -} - -static void add_or_rem_object (GncTaxTable *table, gboolean add) -{ - struct _book_info *bi; - - if (!table) return; - bi = gnc_book_get_data (table->book, _GNC_MOD_NAME); - - if (add) - bi->tables = g_list_insert_sorted (bi->tables, table, - (GCompareFunc)gncTaxTableCompare); - else - bi->tables = g_list_remove (bi->tables, table); -} - -static void addObj (GncTaxTable *table) -{ - gncBusinessAddObject (table->book, _GNC_MOD_NAME, table, &table->guid); - add_or_rem_object (table, TRUE); -} - -static void remObj (GncTaxTable *table) -{ - gncBusinessRemoveObject (table->book, _GNC_MOD_NAME, &table->guid); - add_or_rem_object (table, FALSE); -} - static void _gncTaxTableCreate (QofBook *book) { struct _book_info *bi; @@ -713,8 +779,7 @@ static void _gncTaxTableCreate (QofBook *book) if (!book) return; bi = g_new0 (struct _book_info, 1); - bi->bi.ht = guid_hash_table_new (); - gnc_book_set_data (book, _GNC_MOD_NAME, bi); + qof_book_set_data (book, _GNC_MOD_NAME, bi); } static void _gncTaxTableDestroy (QofBook *book) @@ -723,51 +788,34 @@ static void _gncTaxTableDestroy (QofBook *book) if (!book) return; - bi = gnc_book_get_data (book, _GNC_MOD_NAME); + bi = qof_book_get_data (book, _GNC_MOD_NAME); - /* XXX : Destroy the objects? */ - g_hash_table_destroy (bi->bi.ht); g_list_free (bi->tables); g_free (bi); } -static gboolean _gncTaxTableIsDirty (QofBook *book) +static QofObject gncTaxTableDesc = { - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncTaxTableMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncTaxTableForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - -static QofObject gncTaxTableDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Tax Table", - _gncTaxTableCreate, - _gncTaxTableDestroy, - _gncTaxTableIsDirty, - _gncTaxTableMarkClean, - _gncTaxTableForeach, - NULL /* printable */ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Tax Table", + book_begin: _gncTaxTableCreate, + book_end: _gncTaxTableDestroy, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: NULL, }; gboolean gncTaxTableRegister (void) { - static QofQueryObject params[] = { - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncTaxTableGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncTaxTableGetGUID }, + static QofParam params[] = { + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncTaxTableCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncTaxTableCompare, params); return qof_object_register (&gncTaxTableDesc); } diff --git a/src/business/business-core/gncTaxTable.h b/src/business/business-core/gncTaxTable.h index a454192b3b..7685c1776e 100644 --- a/src/business/business-core/gncTaxTable.h +++ b/src/business/business-core/gncTaxTable.h @@ -1,8 +1,30 @@ -/* - * gncTaxTable.h -- the Gnucash Tax Table interface - * Copyright (C) 2002 Derek Atkins - * Author: Derek Atkins - */ +/********************************************************************\ + * gncTaxTable.h -- the Gnucash Tax Table interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ +/** @addtogroup Business-Engine + @{ */ +/** @file gncTaxTable.h + @breif Tax Table programming interface + @author Copyright (C) 2002 Derek Atkins +*/ #ifndef GNC_TAXTABLE_H_ #define GNC_TAXTABLE_H_ @@ -11,14 +33,19 @@ typedef struct _gncTaxTable GncTaxTable; typedef struct _gncTaxTableEntry GncTaxTableEntry; typedef struct _gncAccountValue GncAccountValue; -#include "gnc-numeric.h" -#include "gnc-book.h" -#include "gnc-date.h" #include "Account.h" +#include "gnc-date.h" +#include "gnc-numeric.h" -#define GNC_TAXTABLE_MODULE_NAME "gncTaxTable" +#include "qofbook.h" +#include "qofinstance.h" +#include "gncBusiness.h" -/* +#define GNC_ID_TAXTABLE "gncTaxTable" +#define GNC_IS_TAXTABLE(obj) (QOF_CHECK_TYPE((obj), GNC_ID_TAXTABLE)) +#define GNC_TAXTABLE(obj) (QOF_CHECK_CAST((obj), GNC_ID_TAXTABLE, GncTaxTable)) + +/** * How to interpret the amount. * You can interpret it as a VALUE or a PERCENT. */ @@ -27,7 +54,7 @@ typedef enum { GNC_AMT_TYPE_PERCENT } GncAmountType; -/* How to interpret the TaxIncluded */ +/** How to interpret the TaxIncluded */ typedef enum { GNC_TAXINCLUDED_YES = 1, GNC_TAXINCLUDED_NO, @@ -40,13 +67,13 @@ gboolean gncAmountStringToType (const char *str, GncAmountType *type); const char * gncTaxIncludedTypeToString (GncTaxIncluded type); gboolean gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type); -/* Create/Destroy Functions */ +/** Create/Destroy Functions */ GncTaxTable * gncTaxTableCreate (QofBook *book); void gncTaxTableDestroy (GncTaxTable *table); GncTaxTableEntry * gncTaxTableEntryCreate (void); void gncTaxTableEntryDestroy (GncTaxTableEntry *entry); -/* Set Functions */ +/** Set Functions */ void gncTaxTableSetName (GncTaxTable *table, const char *name); void gncTaxTableIncRef (GncTaxTable *table); void gncTaxTableDecRef (GncTaxTable *table); @@ -62,13 +89,21 @@ void gncTaxTableChanged (GncTaxTable *table); void gncTaxTableBeginEdit (GncTaxTable *table); void gncTaxTableCommitEdit (GncTaxTable *table); -/* Get Functions */ -GncTaxTable *gncTaxTableLookup (QofBook *book, const GUID *guid); +/** Get Functions */ + +/** Return a pointer to the instance gncTaxTable that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncTaxTable * gncTaxTableLookup (QofBook *book, const GUID *guid); + */ +#define gncTaxTableLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_TAXTABLE, GncTaxTable) + GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name); + GList * gncTaxTableGetTables (QofBook *book); -const GUID *gncTaxTableGetGUID (GncTaxTable *table); -QofBook *gncTaxTableGetBook (GncTaxTable *table); const char *gncTaxTableGetName (GncTaxTable *table); GncTaxTable *gncTaxTableGetParent (GncTaxTable *table); GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new); @@ -84,9 +119,6 @@ gnc_numeric gncTaxTableEntryGetAmount (GncTaxTableEntry *entry); int gncTaxTableCompare (GncTaxTable *a, GncTaxTable *b); int gncTaxTableEntryCompare (GncTaxTableEntry *a, GncTaxTableEntry *b); -GUID gncTaxTableRetGUID (GncTaxTable *table); -GncTaxTable *gncTaxTableLookupDirect (GUID guid, QofBook *book); - /************************************************/ struct _gncAccountValue { @@ -94,20 +126,25 @@ struct _gncAccountValue { gnc_numeric value; }; -/* +/** * This will add value to the account-value for acc, creating a new * list object if necessary */ GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value); -/* Merge l2 into l1. l2 is not touched. */ +/** Merge l2 into l1. l2 is not touched. */ GList *gncAccountValueAddList (GList *l1, GList *l2); -/* return the total for this list */ +/** return the total for this list */ gnc_numeric gncAccountValueTotal (GList *list); -/* Destroy a list of accountvalues */ +/** Destroy a list of accountvalues */ void gncAccountValueDestroy (GList *list); +/** deprecated routine */ +#define gncTaxTableGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x)) +#define gncTaxTableRetGUID(x) (*(qof_instance_get_guid(QOF_INSTANCE(x)))) +#define gncTaxTableLookupDirect(G,B) gncTaxTableLookup((B), &(G)) #endif /* GNC_TAXTABLE_H_ */ +/** @} */ diff --git a/src/business/business-core/gncTaxTableP.h b/src/business/business-core/gncTaxTableP.h index 79ef6c7b7d..db4f02481e 100644 --- a/src/business/business-core/gncTaxTableP.h +++ b/src/business/business-core/gncTaxTableP.h @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncTaxTableP.h -- the Gnucash Tax Table private interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncTaxTableP.h -- the Gnucash Tax Table interface: private interface * Copyright (C) 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -8,10 +30,10 @@ #define GNC_TAXTABLEP_H_ #include "gncTaxTable.h" +#include "qofid-p.h" gboolean gncTaxTableRegister (void); -void gncTaxTableSetGUID (GncTaxTable *table, const GUID *guid); void gncTaxTableSetParent (GncTaxTable *table, GncTaxTable *parent); void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child); void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount); @@ -19,4 +41,29 @@ void gncTaxTableMakeInvisible (GncTaxTable *table); gboolean gncTaxTableGetInvisible (GncTaxTable *table); +/** The gncCloneTaxTable() routine makes a copy of the indicated + * tax table, placing it in the indicated book. It copies + * the tax table name and list of entries. + * It also copies (as needed) both parents and children, so that + * the parent-child relationship is correctly mirrored in the + * clone. + * XXX the refcount is mis-handled. This needs fixin.... + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ +GncTaxTable * gncCloneTaxTable (GncTaxTable *from, QofBook *book); + +/** The gncTaxTableObtainTwin() will find the 'twin' of the + * indicated tax table in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneTaxTable()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncTaxTable * gncTaxTableObtainTwin (GncTaxTable *from, QofBook *book); + +#define gncTaxTableSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G)) + #endif /* GNC_TAXTABLEP_H_ */ diff --git a/src/business/business-core/gncVendor.c b/src/business/business-core/gncVendor.c index e0ba6629ca..82cb07f7ad 100644 --- a/src/business/business-core/gncVendor.c +++ b/src/business/business-core/gncVendor.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncVendor.c -- the Core Vendor Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncVendor.c -- the Core Vendor Interface * Copyright (C) 2001, 2002 Derek Atkins + * Copyright (C) 2003 * Author: Derek Atkins */ @@ -10,64 +32,67 @@ #include #include "guid.h" +#include "qofbook.h" +#include "qofclass.h" +#include "qofid.h" +#include "qofid-p.h" +#include "qofinstance.h" +#include "qofinstance-p.h" +#include "qofobject.h" +#include "qofquery.h" +#include "qofquerycore.h" + #include "messages.h" -#include "gnc-book.h" #include "gnc-commodity.h" #include "gnc-engine-util.h" #include "gnc-event-p.h" -#include "qofid.h" -#include "qofquerycore.h" -#include "qofquery.h" -#include "qofqueryobject.h" #include "gnc-be-utils.h" -#include "qofid-p.h" +#include "gncAddressP.h" +#include "gncBillTermP.h" #include "gncBusiness.h" +#include "gncJobP.h" +#include "gncTaxTableP.h" #include "gncVendor.h" #include "gncVendorP.h" -#include "gncAddress.h" -struct _gncVendor { - QofBook * book; - GUID guid; - char * id; - char * name; - char * notes; - GncBillTerm * terms; - GncAddress * addr; +struct _gncVendor +{ + QofInstance inst; + + char * id; + char * name; + char * notes; + GncBillTerm * terms; + GncAddress * addr; gnc_commodity * currency; - GncTaxIncluded taxincluded; - gboolean active; - GList * jobs; - GncTaxTable* taxtable; - gboolean taxtable_override; - - int editlevel; - gboolean do_free; - - gboolean dirty; + GncTaxTable* taxtable; + gboolean taxtable_override; + GncTaxIncluded taxincluded; + gboolean active; + GList * jobs; }; -static short module = MOD_BUSINESS; +static short module = MOD_BUSINESS; -#define _GNC_MOD_NAME GNC_VENDOR_MODULE_NAME +#define _GNC_MOD_NAME GNC_ID_VENDOR + +/* ============================================================ */ +/* Misc inline funcs */ #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 addObj (GncVendor *vendor); -static void remObj (GncVendor *vendor); - G_INLINE_FUNC void mark_vendor (GncVendor *vendor); G_INLINE_FUNC void mark_vendor (GncVendor *vendor) { - vendor->dirty = TRUE; - gncBusinessSetDirtyFlag (vendor->book, _GNC_MOD_NAME, TRUE); - - gnc_engine_generate_event (&vendor->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + vendor->inst.dirty = TRUE; + qof_collection_mark_dirty (vendor->inst.entity.collection); + gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_MODIFY); } +/* ============================================================== */ /* Create/Destroy Functions */ GncVendor *gncVendorCreate (QofBook *book) @@ -77,19 +102,17 @@ GncVendor *gncVendorCreate (QofBook *book) if (!book) return NULL; vendor = g_new0 (GncVendor, 1); - vendor->book = book; - vendor->dirty = FALSE; + qof_instance_init (&vendor->inst, _GNC_MOD_NAME, book); + vendor->id = CACHE_INSERT (""); vendor->name = CACHE_INSERT (""); vendor->notes = CACHE_INSERT (""); - vendor->addr = gncAddressCreate (book, &vendor->guid, _GNC_MOD_NAME); + vendor->addr = gncAddressCreate (book, &vendor->inst.entity); vendor->taxincluded = GNC_TAXINCLUDED_USEGLOBAL; vendor->active = TRUE; + vendor->jobs = NULL; - qof_entity_guid_new (qof_book_get_entity_table (book), &vendor->guid); - addObj (vendor); - - gnc_engine_generate_event (&vendor->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE); + gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_CREATE); return vendor; } @@ -97,7 +120,7 @@ GncVendor *gncVendorCreate (QofBook *book) void gncVendorDestroy (GncVendor *vendor) { if (!vendor) return; - vendor->do_free = TRUE; + vendor->inst.do_free = TRUE; gncVendorCommitEdit (vendor); } @@ -105,7 +128,7 @@ static void gncVendorFree (GncVendor *vendor) { if (!vendor) return; - gnc_engine_generate_event (&vendor->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY); + gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_DESTROY); CACHE_REMOVE (vendor->id); CACHE_REMOVE (vendor->name); @@ -113,27 +136,84 @@ static void gncVendorFree (GncVendor *vendor) gncAddressDestroy (vendor->addr); g_list_free (vendor->jobs); - remObj (vendor); - if (vendor->terms) gncBillTermDecRef (vendor->terms); if (vendor->taxtable) gncTaxTableDecRef (vendor->taxtable); + qof_instance_release (&vendor->inst); g_free (vendor); } +/** Create a copy of a vendor, placing the copy into a new book. */ +GncVendor * +gncCloneVendor (GncVendor *from, QofBook *book) +{ + GList *node; + GncVendor *vendor; + + if (!book) return NULL; + + vendor = g_new0 (GncVendor, 1); + qof_instance_init (&vendor->inst, _GNC_MOD_NAME, book); + qof_instance_gemini (&vendor->inst, &from->inst); + + vendor->id = CACHE_INSERT (from->id); + vendor->name = CACHE_INSERT (from->name); + vendor->notes = CACHE_INSERT (from->notes); + vendor->addr = gncCloneAddress (from->addr, &vendor->inst.entity, book); + vendor->taxincluded = from->taxincluded; + vendor->taxtable_override = from->taxtable_override; + vendor->active = from->active; + + vendor->terms = gncBillTermObtainTwin (from->terms, book); + gncBillTermIncRef (vendor->terms); + + vendor->currency = gnc_commodity_obtain_twin (from->currency, book); + + vendor->taxtable = gncTaxTableObtainTwin (from->taxtable, book); + gncTaxTableIncRef (vendor->taxtable); + + vendor->jobs = NULL; + for (node=g_list_last(from->jobs); node; node=node->prev) + { + GncJob *job = node->data; + job = gncJobObtainTwin (job, book); + vendor->jobs = g_list_prepend(vendor->jobs, job); + } + + gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_CREATE); + + return vendor; +} + +GncVendor * +gncVendorObtainTwin (GncVendor *from, QofBook *book) +{ + GncVendor *vendor; + if (!book) return NULL; + + vendor = (GncVendor *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!vendor) + { + vendor = gncCloneVendor (from, book); + } + + return vendor; +} + +/* ============================================================== */ /* Set Functions */ #define SET_STR(obj, member, str) { \ - char * tmp; \ - \ - if (!safe_strcmp (member, str)) return; \ - gncVendorBeginEdit (obj); \ - tmp = CACHE_INSERT (str); \ - CACHE_REMOVE (member); \ - member = tmp; \ - } + char * tmp; \ + \ + if (!safe_strcmp (member, str)) return; \ + gncVendorBeginEdit (obj); \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } void gncVendorSetID (GncVendor *vendor, const char *id) { @@ -162,18 +242,6 @@ void gncVendorSetNotes (GncVendor *vendor, const char *notes) gncVendorCommitEdit (vendor); } -void gncVendorSetGUID (GncVendor *vendor, const GUID *guid) -{ - if (!vendor || !guid) return; - if (guid_equal (guid, &vendor->guid)) return; - - gncVendorBeginEdit (vendor); - remObj (vendor); - vendor->guid = *guid; - addObj (vendor); - gncVendorCommitEdit (vendor); -} - void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms) { if (!vendor) return; @@ -184,7 +252,7 @@ void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms) gncBillTermDecRef (vendor->terms); vendor->terms = terms; if (vendor->terms) - gncBillTermDecRef (vendor->terms); + gncBillTermIncRef (vendor->terms); mark_vendor (vendor); gncVendorCommitEdit (vendor); } @@ -245,20 +313,9 @@ void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table) gncVendorCommitEdit (vendor); } +/* ============================================================== */ /* Get Functions */ -QofBook * gncVendorGetBook (GncVendor *vendor) -{ - if (!vendor) return NULL; - return vendor->book; -} - -const GUID * gncVendorGetGUID (GncVendor *vendor) -{ - if (!vendor) return NULL; - return &vendor->guid; -} - const char * gncVendorGetID (GncVendor *vendor) { if (!vendor) return NULL; @@ -327,9 +384,9 @@ void gncVendorAddJob (GncVendor *vendor, GncJob *job) if (g_list_index(vendor->jobs, job) == -1) vendor->jobs = g_list_insert_sorted (vendor->jobs, job, - (GCompareFunc)gncJobCompare); + (GCompareFunc)gncJobCompare); - gnc_engine_generate_event (&vendor->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_MODIFY); } void gncVendorRemoveJob (GncVendor *vendor, GncJob *job) @@ -347,32 +404,39 @@ void gncVendorRemoveJob (GncVendor *vendor, GncJob *job) g_list_free_1 (node); } - gnc_engine_generate_event (&vendor->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY); + gnc_engine_gen_event (&vendor->inst.entity, GNC_EVENT_MODIFY); } void gncVendorBeginEdit (GncVendor *vendor) { - GNC_BEGIN_EDIT (vendor, _GNC_MOD_NAME); + GNC_BEGIN_EDIT (&vendor->inst); } -static void gncVendorOnError (GncVendor *vendor, QofBackendError errcode) +static inline void gncVendorOnError (QofInstance *vendor, QofBackendError errcode) { PERR("Vendor QofBackend Failure: %d", errcode); } -static void gncVendorOnDone (GncVendor *vendor) +static inline void gncVendorOnDone (QofInstance *inst) { - vendor->dirty = FALSE; + GncVendor *vendor = (GncVendor *) inst; gncAddressClearDirty (vendor->addr); } +static inline void vendor_free (QofInstance *inst) +{ + GncVendor *vendor = (GncVendor *) inst; + gncVendorFree (vendor); +} + void gncVendorCommitEdit (GncVendor *vendor) { - GNC_COMMIT_EDIT_PART1 (vendor); - GNC_COMMIT_EDIT_PART2 (vendor, _GNC_MOD_NAME, gncVendorOnError, - gncVendorOnDone, gncVendorFree); + GNC_COMMIT_EDIT_PART1 (&vendor->inst); + GNC_COMMIT_EDIT_PART2 (&vendor->inst, gncVendorOnError, + gncVendorOnDone, vendor_free); } +/* ============================================================== */ /* Other functions */ int gncVendorCompare (GncVendor *a, GncVendor *b) @@ -395,117 +459,59 @@ GList * gncVendorGetJoblist (GncVendor *vendor, gboolean show_all) for (iterator = vendor->jobs; iterator; iterator=iterator->next) { GncJob *j = iterator->data; if (gncJobGetActive (j)) - list = g_list_append (list, j); + list = g_list_append (list, j); } return list; } } -GUID gncVendorRetGUID (GncVendor *vendor) -{ - if (!vendor) - return *guid_null(); - - return vendor->guid; -} - -GncVendor * gncVendorLookupDirect (GUID guid, QofBook *book) -{ - if (!book) return NULL; - return gncVendorLookup (book, &guid); -} - -GncVendor * gncVendorLookup (QofBook *book, const GUID *guid) -{ - if (!book || !guid) return NULL; - return qof_entity_lookup (gnc_book_get_entity_table (book), - guid, _GNC_MOD_NAME); -} - gboolean gncVendorIsDirty (GncVendor *vendor) { if (!vendor) return FALSE; - return (vendor->dirty || gncAddressIsDirty (vendor->addr)); + return (vendor->inst.dirty || gncAddressIsDirty (vendor->addr)); } +/* ============================================================== */ /* Package-Private functions */ -static void addObj (GncVendor *vendor) -{ - gncBusinessAddObject (vendor->book, _GNC_MOD_NAME, vendor, &vendor->guid); -} - -static void remObj (GncVendor *vendor) -{ - gncBusinessRemoveObject (vendor->book, _GNC_MOD_NAME, &vendor->guid); -} - -static void _gncVendorCreate (QofBook *book) -{ - gncBusinessCreate (book, _GNC_MOD_NAME); -} - -static void _gncVendorDestroy (QofBook *book) -{ - gncBusinessDestroy (book, _GNC_MOD_NAME); -} - -static gboolean _gncVendorIsDirty (QofBook *book) -{ - return gncBusinessIsDirty (book, _GNC_MOD_NAME); -} - -static void _gncVendorMarkClean (QofBook *book) -{ - gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE); -} - -static void _gncVendorForeach (QofBook *book, QofEntityForeachCB cb, - gpointer user_data) -{ - gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data); -} - static const char * _gncVendorPrintable (gpointer item) { - GncVendor *v; - + GncVendor *v = item; if (!item) return NULL; - - v = item; return v->name; } -static QofObject gncVendorDesc = { - QOF_OBJECT_VERSION, - _GNC_MOD_NAME, - "Vendor", - _gncVendorCreate, - _gncVendorDestroy, - _gncVendorIsDirty, - _gncVendorMarkClean, - _gncVendorForeach, - _gncVendorPrintable +static QofObject gncVendorDesc = +{ + interface_version: QOF_OBJECT_VERSION, + e_type: _GNC_MOD_NAME, + type_label: "Vendor", + book_begin: NULL, + book_end: NULL, + is_dirty: qof_collection_is_dirty, + mark_clean: qof_collection_mark_clean, + foreach: qof_collection_foreach, + printable: _gncVendorPrintable }; gboolean gncVendorRegister (void) { - static QofQueryObject params[] = { - { VENDOR_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncVendorGetID }, - { VENDOR_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncVendorGetName }, - { VENDOR_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncVendorGetAddr }, - { QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncVendorGetBook }, - { QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncVendorGetGUID }, - { QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncVendorGetActive }, + static QofParam params[] = { + { VENDOR_ID, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetID, NULL }, + { VENDOR_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetName, NULL }, + { VENDOR_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncVendorGetAddr, NULL }, + { QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, + { QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, + { QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncVendorGetActive, NULL }, { NULL }, }; - qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncVendorCompare, params); + qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncVendorCompare, params); return qof_object_register (&gncVendorDesc); } gint64 gncVendorNextID (QofBook *book) { - return gnc_book_get_counter (book, _GNC_MOD_NAME); + return qof_book_get_counter (book, _GNC_MOD_NAME); } diff --git a/src/business/business-core/gncVendor.h b/src/business/business-core/gncVendor.h index d319a09d38..6d547ad282 100644 --- a/src/business/business-core/gncVendor.h +++ b/src/business/business-core/gncVendor.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncVendor.h -- the Core Vendor Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncVendor.h -- the Core Vendor Interface * Copyright (C) 2001, 2002 Derek Atkins * Author: Derek Atkins */ @@ -9,13 +30,17 @@ typedef struct _gncVendor GncVendor; -#include "gnc-book.h" #include "gncAddress.h" #include "gncBillTerm.h" #include "gncTaxTable.h" #include "gncJob.h" +#include "qofbook.h" +#include "qofid.h" +#include "qofinstance.h" -#define GNC_VENDOR_MODULE_NAME "gncVendor" +#define GNC_ID_VENDOR "gncVendor" +#define GNC_IS_VENDOR(obj) (QOF_CHECK_TYPE((obj), GNC_ID_VENDOR)) +#define GNC_VENDOR(obj) (QOF_CHECK_CAST((obj), GNC_ID_VENDOR, GncVendor)) /* Create/Destroy Functions */ @@ -43,8 +68,6 @@ void gncVendorCommitEdit (GncVendor *vendor); /* Get Functions */ -QofBook * gncVendorGetBook (GncVendor *vendor); -const GUID * gncVendorGetGUID (GncVendor *vendor); const char * gncVendorGetID (GncVendor *vendor); const char * gncVendorGetName (GncVendor *vendor); GncAddress * gncVendorGetAddr (GncVendor *vendor); @@ -57,17 +80,30 @@ gboolean gncVendorGetActive (GncVendor *vendor); gboolean gncVendorGetTaxTableOverride (GncVendor *vendor); GncTaxTable* gncVendorGetTaxTable (GncVendor *vendor); +/** XXX should be renamed to RetJobList to be consistent with + * other usage, since caller must free the copied list + */ GList * gncVendorGetJoblist (GncVendor *vendor, gboolean show_all); - -GUID gncVendorRetGUID (GncVendor *vendor); -GncVendor * gncVendorLookupDirect (GUID guid, QofBook *book); - -GncVendor * gncVendorLookup (QofBook *book, const GUID *guid); gboolean gncVendorIsDirty (GncVendor *vendor); int gncVendorCompare (GncVendor *a, GncVendor *b); +/** Return a pointer to the instance gncVendor that is identified + * by the guid, and is residing in the book. Returns NULL if the + * instance can't be found. + * Equivalent function prototype is + * GncVendor * gncVendorLookup (QofBook *book, const GUID *guid); + */ +#define gncVendorLookup(book,guid) \ + QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_VENDOR, GncVendor) + #define VENDOR_ID "id" #define VENDOR_NAME "name" #define VENDOR_ADDR "addr" +/** deprecated functions */ +#define gncVendorGetBook(X) qof_instance_get_book (QOF_INSTANCE(X)) +#define gncVendorGetGUID(X) qof_instance_get_guid (QOF_INSTANCE(X)) +#define gncVendorRetGUID(X) (*(qof_instance_get_guid (QOF_INSTANCE(X)))) +#define gncVendorLookupDirect(G,B) gncVendorLookup((B),&(G)) + #endif /* GNC_VENDOR_H_ */ diff --git a/src/business/business-core/gncVendorP.h b/src/business/business-core/gncVendorP.h index 93372f55b8..50695b8b44 100644 --- a/src/business/business-core/gncVendorP.h +++ b/src/business/business-core/gncVendorP.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncVendorP.h -- the Core Vendor Interface * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncVendorP.h -- the Core Vendor Interface * Copyright (C) 2001 Derek Atkins * Author: Derek Atkins */ @@ -8,9 +29,31 @@ #define GNC_VENDORP_H_ #include "gncVendor.h" +#include "qofid-p.h" gboolean gncVendorRegister (void); gint64 gncVendorNextID (QofBook *book); -void gncVendorSetGUID (GncVendor *vendor, const GUID *guid); + +/** The gncCloneVendor() routine makes a copy of the indicated + * vendor, placing it in the indicated book. It copies + * the name, notes, address, etc. + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ + +GncVendor * gncCloneVendor (GncVendor *from, QofBook *); + +/** The gncVendorObtainTwin() will find the 'twin' of the + * indicated vendor in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneVendor()) and placed into the book. + * + * We called this routine 'Obtain' instead of "Get" to distinguish + * it from the other Get routines, which work in fundamentally + * different ways. + */ +GncVendor * gncVendorObtainTwin (GncVendor *from, QofBook *book); +#define gncVendorSetGUID(V,G) qof_entity_set_guid(QOF_ENTITY(V),(G)) + #endif /* GNC_VENDORP_H_ */ diff --git a/src/business/business-core/test/Makefile.am b/src/business/business-core/test/Makefile.am index 361e376f63..64f25976e4 100644 --- a/src/business/business-core/test/Makefile.am +++ b/src/business/business-core/test/Makefile.am @@ -13,6 +13,7 @@ LDADD = \ ${top_builddir}/src/test-core/libgncmod-test.la \ ${top_builddir}/src/engine/libgncmod-engine.la \ ${top_builddir}/src/engine/libgw-engine.la \ + ${top_builddir}/src/backend/file/libgncmod-backend-file.la \ ../libgncmod-business-core.la \ ../libgw-business-core.la \ ${GLIB_LIBS} \