> Could you use "svn diff" or "diff -u" and re-attach please? > A 'standard diff' is very hard to read/follow.
Attached. Apply with patch -p0 from within the source directory. Jamie is working on the proposal I made in my Oct 23 post, "Proposal for business, multi-currency support" http://lists.gnucash.org/pipermail/gnucash-devel/2008-October/024162.html This patch is a first step towards that. Mark Jenkins cc Jamie cc gnucash-devel
Index: src/business/business-gnome/business-gnome-utils.h =================================================================== --- src/business/business-gnome/business-gnome-utils.h (.../trunk) (revision 150) +++ src/business/business-gnome/business-gnome-utils.h (.../branches/multicurrency-patch) (revision 151) @@ -62,6 +62,9 @@ /* Return a list of account-types based on the owner type */ GList * gnc_business_account_types (GncOwner *owner); +/* Return a list of currencies associated with the owner */ +GList * gnc_business_commodities (GncOwner *owner); + /* Fill in a combo box with the appropriate list of accounts */ void gnc_fill_account_select_combo (GtkWidget *combo, GNCBook *book, GList *acct_types); Index: src/business/business-gnome/dialog-date-close.c =================================================================== --- src/business/business-gnome/dialog-date-close.c (.../trunk) (revision 150) +++ src/business/business-gnome/dialog-date-close.c (.../branches/multicurrency-patch) (revision 151) @@ -47,6 +47,7 @@ GncBillTerm *terms; Timespec *ts, *ts2; GList * acct_types; + GList * acct_commodities; GNCBook *book; Account *acct; char **memo; @@ -106,7 +107,7 @@ GNCAccountSel *gas = GNC_ACCOUNT_SEL (ddc->acct_combo); /* How do I set the book? */ - gnc_account_sel_set_acct_filters( gas, ddc->acct_types ); + gnc_account_sel_set_acct_filters( gas, ddc->acct_types, ddc->acct_commodities ); gnc_account_sel_set_new_account_ability( gas, TRUE ); gnc_account_sel_set_new_account_modal( gas, TRUE ); gnc_account_sel_set_account( gas, ddc->acct, set_default_acct ); @@ -228,8 +229,8 @@ const char *question_check_message, gboolean ok_is_default, gboolean set_default_acct, - GList * acct_types, GNCBook *book, - GncBillTerm *terms, + GList * acct_types, GList * acct_commodities, + GNCBook *book, GncBillTerm *terms, /* Returned Data... */ Timespec *ddue, Timespec *post, char **memo, Account **acct, gboolean *answer) @@ -253,6 +254,7 @@ ddc->ts2 = post; ddc->book = book; ddc->acct_types = acct_types; + ddc->acct_commodities = acct_commodities; ddc->acct = *acct; ddc->memo = memo; ddc->terms = terms; Index: src/business/business-gnome/dialog-date-close.h =================================================================== --- src/business/business-gnome/dialog-date-close.h (.../trunk) (revision 150) +++ src/business/business-gnome/dialog-date-close.h (.../branches/multicurrency-patch) (revision 151) @@ -52,9 +52,9 @@ const char *acct_label_message, const char *question_check_message, gboolean ok_is_default, - gboolean set_default_acct, - GList * acct_types, GNCBook *book, - GncBillTerm *terms, + gboolean set_default_acct, + GList * acct_types, GList * acct_commodities, + GNCBook *book, GncBillTerm *terms, /* Returned Data... */ Timespec *ddue, Timespec *post, char **memo, Account **acct, gboolean *answer); Index: src/business/business-gnome/dialog-employee.c =================================================================== --- src/business/business-gnome/dialog-employee.c (.../trunk) (revision 150) +++ src/business/business-gnome/dialog-employee.c (.../branches/multicurrency-patch) (revision 151) @@ -474,7 +474,7 @@ edit = gnc_account_sel_new(); acct_types = g_list_prepend(NULL, (gpointer)ACCT_TYPE_CREDIT); - gnc_account_sel_set_acct_filters (GNC_ACCOUNT_SEL(edit), acct_types); + gnc_account_sel_set_acct_filters (GNC_ACCOUNT_SEL(edit), acct_types, NULL); g_list_free (acct_types); ew->ccard_acct_sel = edit; Index: src/business/business-gnome/dialog-invoice.c =================================================================== --- src/business/business-gnome/dialog-invoice.c (.../trunk) (revision 150) +++ src/business/business-gnome/dialog-invoice.c (.../branches/multicurrency-patch) (revision 151) @@ -602,6 +602,7 @@ char *message, *memo, *ddue_label, *post_label, *acct_label, *question_label; Account *acc = NULL; GList * acct_types = NULL; + GList * acct_commodities = NULL; Timespec ddue, postdate; gboolean accumulate; QofInstance *owner_inst; @@ -650,6 +651,9 @@ /* Determine the type of account to post to */ acct_types = gnc_business_account_types (&(iw->owner)); + /* Determine which commodity we're working with */ + acct_commodities = gnc_business_commodities(&(iw->owner)); + /* Get the due date and posted account */ timespecFromTime_t (&postdate, time(NULL)); ddue = postdate; @@ -665,7 +669,7 @@ if (!gnc_dialog_dates_acct_question_parented (iw_get_window(iw), message, ddue_label, post_label, acct_label, question_label, TRUE, TRUE, - acct_types, iw->book, iw->terms, + acct_types, acct_commodities, iw->book, iw->terms, &ddue, &postdate, &memo, &acc, &accumulate)) return; Index: src/business/business-gnome/business-gnome-utils.c =================================================================== --- src/business/business-gnome/business-gnome-utils.c (.../trunk) (revision 150) +++ src/business/business-gnome/business-gnome-utils.c (.../branches/multicurrency-patch) (revision 151) @@ -366,6 +366,14 @@ } } +GList * +gnc_business_commodities (GncOwner *owner) +{ + g_return_val_if_fail (owner, NULL); + + return (g_list_prepend (NULL, gncOwnerGetCurrency(owner))); +} + /*********************************************************************/ /* Option Menu creation */ Index: src/gnome-utils/gnc-account-sel.c =================================================================== --- src/gnome-utils/gnc-account-sel.c (.../trunk) (revision 150) +++ src/gnome-utils/gnc-account-sel.c (.../branches/multicurrency-patch) (revision 151) @@ -31,10 +31,12 @@ #include "dialog-account.h" #include "GNCId.h" #include "gnc-account-sel.h" +#include "gnc-commodity.h" #include "gnc-exp-parser.h" #include "gnc-gtk-utils.h" #include "gnc-ui-util.h" #include "qof.h" +#include "gnc-session.h" #define ACCT_DATA_TAG "gnc-account-sel_acct" @@ -249,6 +251,17 @@ return; } } + + if ( atnd->gas->acctCommodityFilters ) { + if ( g_list_find_custom( atnd->gas->acctCommodityFilters, + GINT_TO_POINTER(xaccAccountGetCommodity( a )), + gnc_commodity_compare) + == NULL ) { + return; + } + } + + *atnd->outList = g_list_append( *atnd->outList, a ); } @@ -324,19 +337,54 @@ void -gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *filters ) +gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *typeFilters, GList *commodityFilters ) { + GList *src=NULL; + GList *dest=NULL; + gnc_commodity* commClone=NULL; + if ( gas->acctTypeFilters != NULL ) { g_list_free( gas->acctTypeFilters ); gas->acctTypeFilters = NULL; } - /* If it's null, then no filters exist. */ - if ( ! filters ) { + + if ( gas->acctCommodityFilters != NULL) { + g_list_free( gas->acctCommodityFilters ); + gas->acctCommodityFilters = NULL; + } + + /* If both filters are null, then no filters exist. */ + if (( ! typeFilters ) && ( ! commodityFilters)) { return; } + /* This works because the GNCAccountTypes in the list are * ints-casted-as-pointers. */ - gas->acctTypeFilters = g_list_copy( filters ); + if (typeFilters) + { + gas->acctTypeFilters = g_list_copy( typeFilters ); + } + + if (commodityFilters) + { + src = commodityFilters; + + while (src->data != NULL) + { + //gnc_commodity_clone would have been nice but it expects me to + //insert the clone into a book, which I don't want to do. + commClone = gnc_commodity_new(qof_session_get_book(gnc_get_current_session()), "","","","",1); + gnc_commodity_copy(commClone, src->data); + dest = g_list_prepend(dest, commClone); + if (src->next == NULL) + { + break; + } + src = src->next; + } + gas->acctCommodityFilters = dest; + } + gas_populate_list( gas ); } Index: src/gnome-utils/gnc-account-sel.h =================================================================== --- src/gnome-utils/gnc-account-sel.h (.../trunk) (revision 150) +++ src/gnome-utils/gnc-account-sel.h (.../branches/multicurrency-patch) (revision 151) @@ -46,6 +46,7 @@ GtkListStore *store; GtkComboBoxEntry *combo; GList *acctTypeFilters; + GList *acctCommodityFilters; gint eventHandlerId; /* The state of this pointer also serves as a flag about what state * the widget is in WRT the new-account-button ability. */ @@ -81,10 +82,11 @@ /** * The GNCAccountSel can be setup to filter the accounts displayed. - * @param filters A GList of GNCAccountType identifiers which are allowed. + * @param typeFilters A GList of GNCAccountType identifiers which are allowed. + * @param commodityFilters A GList of gnc_commodity types which are allowed. * The list is copied, of course. **/ -void gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *filters ); +void gnc_account_sel_set_acct_filters( GNCAccountSel *gas, GList *typeFilters, GList *commodityFilters ); /** * Conditional inclusion of a new-account button to the right of the Index: src/gnome-utils/dialog-options.c =================================================================== --- src/gnome-utils/dialog-options.c (.../trunk) (revision 150) +++ src/gnome-utils/dialog-options.c (.../branches/multicurrency-patch) (revision 151) @@ -1828,7 +1828,7 @@ acct_type_list = gnc_option_get_account_type_list(option); value = gnc_account_sel_new(); - gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(value), acct_type_list); + gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(value), acct_type_list, NULL); g_signal_connect(value, "account_sel_changed", G_CALLBACK(gnc_option_changed_widget_cb), option); Index: src/gnome-utils/dialog-book-close.c =================================================================== --- src/gnome-utils/dialog-book-close.c (.../trunk) (revision 150) +++ src/gnome-utils/dialog-book-close.c (.../branches/multicurrency-patch) (revision 151) @@ -333,7 +333,7 @@ box = glade_xml_get_widget(xml, "income_acct_box"); cbw->income_acct_widget = gnc_account_sel_new(); gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(cbw->income_acct_widget), - equity_list); + equity_list, NULL); gnc_account_sel_set_new_account_ability(GNC_ACCOUNT_SEL(cbw->income_acct_widget), TRUE); gtk_box_pack_start(GTK_BOX(box), cbw->income_acct_widget, TRUE, TRUE, 0); @@ -341,7 +341,7 @@ box = glade_xml_get_widget(xml, "expense_acct_box"); cbw->expense_acct_widget = gnc_account_sel_new(); gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(cbw->expense_acct_widget), - equity_list); + equity_list, NULL); gnc_account_sel_set_new_account_ability(GNC_ACCOUNT_SEL(cbw->expense_acct_widget), TRUE); gtk_box_pack_start(GTK_BOX(box), cbw->expense_acct_widget, TRUE, TRUE, 0); Index: src/gnome/druid-loan.c =================================================================== --- src/gnome/druid-loan.c (.../trunk) (revision 150) +++ src/gnome/druid-loan.c (.../branches/multicurrency-patch) (revision 151) @@ -503,7 +503,7 @@ gas, gas_data[i].newAcctAbility ); if ( gas_data[i].allowableAccounts != NULL ) { gnc_account_sel_set_acct_filters( - gas, gas_data[i].allowableAccounts ); + gas, gas_data[i].allowableAccounts, NULL ); } gtk_container_add( GTK_CONTAINER(a), GTK_WIDGET(gas) ); Index: src/gnome/gnc-plugin-page-account-tree.c =================================================================== --- src/gnome/gnc-plugin-page-account-tree.c (.../trunk) (revision 150) +++ src/gnome/gnc-plugin-page-account-tree.c (.../branches/multicurrency-patch) (revision 151) @@ -852,7 +852,7 @@ filter = g_object_get_data(G_OBJECT(dialog), DELETE_DIALOG_FILTER); /* Setting the account type filter triggers GNCAccountSel population. */ - gnc_account_sel_set_acct_filters (gas, filter); + gnc_account_sel_set_acct_filters (gas, filter, NULL); /* Accounts to be deleted must be removed. */ gnc_account_sel_purge_account( gas, account, exclude_subaccounts); Index: src/engine/gnc-commodity.c =================================================================== --- src/engine/gnc-commodity.c (.../trunk) (revision 150) +++ src/engine/gnc-commodity.c (.../branches/multicurrency-patch) (revision 151) @@ -889,6 +889,7 @@ CommodityPrivate* dest_priv = GET_PRIVATE(dest); gnc_commodity_set_fullname (dest, src_priv->fullname); + gnc_commodity_set_mnemonic (dest, gnc_commodity_get_mnemonic(src)); dest_priv->namespace = src_priv->namespace; gnc_commodity_set_fraction (dest, src_priv->fraction); gnc_commodity_set_cusip (dest, src_priv->cusip); @@ -1494,6 +1495,17 @@ return TRUE; } +int gnc_commodity_compare(const gnc_commodity * a, const gnc_commodity * b) +{ + if (gnc_commodity_equal(a,b)) + { + return 0; + } + else + { + return 1; + } +} /************************************************************ * Namespace functions * Index: src/engine/gnc-commodity.h =================================================================== --- src/engine/gnc-commodity.h (.../trunk) (revision 150) +++ src/engine/gnc-commodity.h (.../branches/multicurrency-patch) (revision 151) @@ -642,6 +642,15 @@ * fullname, exchange private code and fraction. */ gboolean gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b); + +/** This routine returns 0 if the two commodities are equal, 1 otherwise. + * Commodities are equal if they have the same namespace, mnemonic, + * fullname, exchange private code and fraction. + * This function is useful for list-traversal comparison purposes where + * The semantics are 0, <0, or >0 (equal, greater than, less than) rather + * than "true or false" + */ +int gnc_commodity_compare(const gnc_commodity * a, const gnc_commodity * b); /** @} */
_______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel