void gnc_ui_payment_window_set_amount (PaymentWindow *pw, gnc_numeric amount) { g_assert(pw); /* Debits are negative, credits are positive */ if (gnc_numeric_positive_p (amount)) { gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(pw->amount_credit_edit), amount); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(pw->amount_debit_edit), gnc_numeric_zero ()); } else { gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(pw->amount_debit_edit), gnc_numeric_neg (amount)); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(pw->amount_credit_edit), gnc_numeric_zero ()); } }
/* Copy the values in the financial_info structure to the GUI */ static void fi_to_gui(FinCalcDialog *fcd) { const gnc_commodity *commodity; static char string[64]; gnc_numeric total; gnc_numeric npp; gnc_numeric pmt; int i; if (fcd == NULL) return; npp = gnc_numeric_create (fcd->financial_info.npp, 1); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]), npp); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[INTEREST_RATE]), fcd->financial_info.ir); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PRESENT_VALUE]), fcd->financial_info.pv); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PERIODIC_PAYMENT]), fcd->financial_info.pmt); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[FUTURE_VALUE]), -fcd->financial_info.fv); pmt = double_to_gnc_numeric (fcd->financial_info.pmt, 100000, GNC_HOW_RND_ROUND_HALF_UP); commodity = gnc_default_currency (); total = gnc_numeric_mul (npp, pmt, gnc_commodity_get_fraction (commodity), GNC_HOW_RND_ROUND_HALF_UP); xaccSPrintAmount (string, total, gnc_default_print_info (FALSE)); gtk_label_set_text (GTK_LABEL(fcd->payment_total_label), string); i = normalize_period(&fcd->financial_info.CF); gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->compounding_combo), i); i = normalize_period(&fcd->financial_info.PF); gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->payment_combo), i); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fcd->end_of_period_radio), !fcd->financial_info.bep); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(fcd->discrete_compounding_radio), fcd->financial_info.disc); }
static CustomerWindow * gnc_customer_new_window (QofBook *bookp, GncCustomer *cust) { CustomerWindow *cw; GtkBuilder *builder; GtkWidget *hbox, *edit; gnc_commodity *currency; GNCPrintAmountInfo print_info; /* * Find an existing window for this customer. If found, bring it to * the front. */ if (cust) { GncGUID customer_guid; customer_guid = *gncCustomerGetGUID(cust); cw = gnc_find_first_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS, find_handler, &customer_guid); if (cw) { gtk_window_present (GTK_WINDOW(cw->dialog)); return(cw); } } /* Find the default currency */ if (cust) currency = gncCustomerGetCurrency (cust); else currency = gnc_default_currency (); /* * No existing customer window found. Build a new one. */ cw = g_new0 (CustomerWindow, 1); cw->book = bookp; /* Find the dialog */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-customer.glade", "terms_store"); gnc_builder_add_from_file (builder, "dialog-customer.glade", "tax_included_store"); gnc_builder_add_from_file (builder, "dialog-customer.glade", "taxtable_store"); gnc_builder_add_from_file (builder, "dialog-customer.glade", "Customer Dialog"); cw->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "Customer Dialog")); g_object_set_data (G_OBJECT (cw->dialog), "dialog_info", cw); /* Get entry points */ cw->id_entry = GTK_WIDGET (gtk_builder_get_object (builder, "id_entry")); cw->company_entry = GTK_WIDGET (gtk_builder_get_object (builder, "company_entry")); cw->name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry")); cw->addr1_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr1_entry")); cw->addr2_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr2_entry")); cw->addr3_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr3_entry")); cw->addr4_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr4_entry")); cw->phone_entry = GTK_WIDGET (gtk_builder_get_object (builder, "phone_entry")); cw->fax_entry = GTK_WIDGET (gtk_builder_get_object (builder, "fax_entry")); cw->email_entry = GTK_WIDGET (gtk_builder_get_object (builder, "email_entry")); cw->shipname_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipname_entry")); cw->shipaddr1_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr1_entry")); cw->shipaddr2_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr2_entry")); cw->shipaddr3_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr3_entry")); cw->shipaddr4_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr4_entry")); cw->shipphone_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipphone_entry")); cw->shipfax_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipfax_entry")); cw->shipemail_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipemail_entry")); cw->active_check = GTK_WIDGET (gtk_builder_get_object (builder, "active_check")); cw->taxincluded_menu = GTK_WIDGET (gtk_builder_get_object (builder, "tax_included_menu")); cw->notes_text = GTK_WIDGET (gtk_builder_get_object (builder, "notes_text")); cw->terms_menu = GTK_WIDGET (gtk_builder_get_object (builder, "terms_menu")); cw->taxtable_check = GTK_WIDGET (gtk_builder_get_object (builder, "taxtable_button")); cw->taxtable_menu = GTK_WIDGET (gtk_builder_get_object (builder, "taxtable_menu")); /* Currency */ edit = gnc_currency_edit_new(); gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(edit), currency); cw->currency_edit = edit; hbox = GTK_WIDGET (gtk_builder_get_object (builder, "currency_box")); gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); /* DISCOUNT: Percentage Value */ edit = gnc_amount_edit_new(); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); print_info = gnc_integral_print_info (); print_info.max_decimal_places = 5; gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000); cw->discount_amount = edit; gtk_widget_show (edit); hbox = GTK_WIDGET (gtk_builder_get_object (builder, "discount_box")); gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); /* CREDIT: Monetary Value */ edit = gnc_amount_edit_new(); print_info = gnc_commodity_print_info (currency, FALSE); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), gnc_commodity_get_fraction (currency)); cw->credit_amount = edit; gtk_widget_show (edit); hbox = GTK_WIDGET (gtk_builder_get_object (builder, "credit_box")); gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); /* Setup signals */ gtk_builder_connect_signals_full( builder, gnc_builder_connect_full_func, cw); /* Setup initial values */ if (cust != NULL) { GtkTextBuffer* text_buffer; GncAddress *addr, *shipaddr; const char *string; cw->dialog_type = EDIT_CUSTOMER; cw->customer_guid = *gncCustomerGetGUID (cust); addr = gncCustomerGetAddr (cust); shipaddr = gncCustomerGetShipAddr (cust); gtk_entry_set_text (GTK_ENTRY (cw->id_entry), gncCustomerGetID (cust)); gtk_entry_set_text (GTK_ENTRY (cw->company_entry), gncCustomerGetName (cust)); /* Setup Address */ gtk_entry_set_text (GTK_ENTRY (cw->name_entry), gncAddressGetName (addr)); gtk_entry_set_text (GTK_ENTRY (cw->addr1_entry), gncAddressGetAddr1 (addr)); gtk_entry_set_text (GTK_ENTRY (cw->addr2_entry), gncAddressGetAddr2 (addr)); gtk_entry_set_text (GTK_ENTRY (cw->addr3_entry), gncAddressGetAddr3 (addr)); gtk_entry_set_text (GTK_ENTRY (cw->addr4_entry), gncAddressGetAddr4 (addr)); gtk_entry_set_text (GTK_ENTRY (cw->phone_entry), gncAddressGetPhone (addr)); gtk_entry_set_text (GTK_ENTRY (cw->fax_entry), gncAddressGetFax (addr)); gtk_entry_set_text (GTK_ENTRY (cw->email_entry), gncAddressGetEmail (addr)); /* Setup Ship-to Address */ gtk_entry_set_text (GTK_ENTRY (cw->shipname_entry), gncAddressGetName (shipaddr)); gtk_entry_set_text (GTK_ENTRY (cw->shipaddr1_entry), gncAddressGetAddr1 (shipaddr)); gtk_entry_set_text (GTK_ENTRY (cw->shipaddr2_entry), gncAddressGetAddr2 (shipaddr)); gtk_entry_set_text (GTK_ENTRY (cw->shipaddr3_entry), gncAddressGetAddr3 (shipaddr)); gtk_entry_set_text (GTK_ENTRY (cw->shipaddr4_entry), gncAddressGetAddr4 (shipaddr)); gtk_entry_set_text (GTK_ENTRY (cw->shipphone_entry), gncAddressGetPhone (shipaddr)); gtk_entry_set_text (GTK_ENTRY (cw->shipfax_entry), gncAddressGetFax (shipaddr)); gtk_entry_set_text (GTK_ENTRY (cw->shipemail_entry), gncAddressGetEmail (shipaddr)); /* Set toggle buttons */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->active_check), gncCustomerGetActive (cust)); string = gncCustomerGetNotes (cust); text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(cw->notes_text)); gtk_text_buffer_set_text (text_buffer, string, -1); cw->component_id = gnc_register_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS, gnc_customer_window_refresh_handler, gnc_customer_window_close_handler, cw); cw->terms = gncCustomerGetTerms (cust); } else { cust = gncCustomerCreate (bookp); cw->customer_guid = *gncCustomerGetGUID (cust); cw->dialog_type = NEW_CUSTOMER; cw->component_id = gnc_register_gui_component (DIALOG_NEW_CUSTOMER_CM_CLASS, gnc_customer_window_refresh_handler, gnc_customer_window_close_handler, cw); /* XXX: get the global-default terms */ cw->terms = NULL; } /* I know that cust exists here -- either passed in or just created */ cw->taxincluded = gncCustomerGetTaxIncluded (cust); gnc_taxincluded_combo (GTK_COMBO_BOX(cw->taxincluded_menu), cw->taxincluded); gnc_billterms_combo (GTK_COMBO_BOX(cw->terms_menu), bookp, TRUE, cw->terms); cw->taxtable = gncCustomerGetTaxTable (cust); gnc_taxtables_combo (GTK_COMBO_BOX(cw->taxtable_menu), bookp, TRUE, cw->taxtable); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->taxtable_check), gncCustomerGetTaxTableOverride (cust)); gnc_customer_taxtable_check_cb (GTK_TOGGLE_BUTTON (cw->taxtable_check), cw); /* Set up the addr line quickfill */ cw->addr2_quickfill = gnc_get_shared_address_addr2_quickfill(cw->book, ADDR_QUICKFILL); cw->addr3_quickfill = gnc_get_shared_address_addr3_quickfill(cw->book, ADDR_QUICKFILL); cw->addr4_quickfill = gnc_get_shared_address_addr4_quickfill(cw->book, ADDR_QUICKFILL); /* Set the Discount, and Credit amounts */ gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount), gncCustomerGetDiscount (cust)); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->credit_amount), gncCustomerGetCredit (cust)); gnc_gui_component_watch_entity_type (cw->component_id, GNC_CUSTOMER_MODULE_NAME, QOF_EVENT_MODIFY | QOF_EVENT_DESTROY); gtk_widget_show_all (cw->dialog); g_object_unref(G_OBJECT(builder)); return cw; }
static PaymentWindow * new_payment_window (GncOwner *owner, QofBook *book, GncInvoice *invoice) { PaymentWindow *pw; GtkBuilder *builder; GtkWidget *box, *label, *credit_box, *debit_box; GtkTreeSelection *selection; GtkTreeViewColumn *column; GtkCellRenderer *renderer; char * cm_class = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER ? DIALOG_PAYMENT_CUSTOMER_CM_CLASS : DIALOG_PAYMENT_VENDOR_CM_CLASS); /* * Find an existing payment window. If found, bring it to * the front. If we have an actual owner, then set it in * the window. */ pw = gnc_find_first_gui_component (cm_class, find_handler, NULL); if (pw) { if (gncOwnerIsValid(owner)) gnc_payment_set_owner (pw, owner); // Reset the setting about the pre-existing TXN pw->pre_existing_txn = NULL; gtk_window_present (GTK_WINDOW(pw->dialog)); return(pw); } /* Ok, we need a new window */ pw = g_new0 (PaymentWindow, 1); pw->book = book; gncOwnerCopy (owner, &(pw->owner)); /* Compute the post-to account types */ pw->acct_types = gncOwnerGetAccountTypesList (owner); if (gncOwnerIsValid(owner)) pw->acct_commodities = gncOwnerGetCommoditiesList (owner); /* Open and read the Glade File */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-payment.glade", "docs_list_hor_adj"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "docs_list_vert_adj"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "docs_list_model"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "post_combo_model"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "Payment Dialog"); pw->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "Payment Dialog")); /* Grab the widgets and build the dialog */ pw->payment_warning = GTK_WIDGET (gtk_builder_get_object (builder, "payment_warning")); pw->ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "okbutton")); pw->num_entry = GTK_WIDGET (gtk_builder_get_object (builder, "num_entry")); pw->memo_entry = GTK_WIDGET (gtk_builder_get_object (builder, "memo_entry")); pw->post_combo = GTK_WIDGET (gtk_builder_get_object (builder, "post_combo")); gtk_combo_box_set_entry_text_column( GTK_COMBO_BOX( pw->post_combo ), 0 ); gnc_cbwe_require_list_item(GTK_COMBO_BOX(pw->post_combo)); label = GTK_WIDGET (gtk_builder_get_object (builder, "owner_label")); box = GTK_WIDGET (gtk_builder_get_object (builder, "owner_box")); pw->owner_choice = gnc_owner_select_create (label, box, book, owner); /* Some terminology: * Invoices are paid, credit notes are refunded. * A customer payment is a credit action, paying a vendor is debit * * So depending on the owner the payment amount should be considered * credit (customer) or debit (vendor/employee) and refunds should be * considered debit (customer) or credit (vendor/employee). * For visual consistency, the dialog box will always show a payment and * a refund field. Internally they are treated as credit or debit depending * on the owner type. */ if (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER) { debit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_refund_box")); credit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_payment_box")); } else { debit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_payment_box")); credit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_refund_box")); } pw->amount_debit_edit = gnc_amount_edit_new (); gtk_box_pack_start (GTK_BOX (debit_box), pw->amount_debit_edit, TRUE, TRUE, 0); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (pw->amount_debit_edit), TRUE); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_debit_edit), gnc_numeric_zero()); g_signal_connect(G_OBJECT(gnc_amount_edit_gtk_entry(GNC_AMOUNT_EDIT(pw->amount_debit_edit))), "focus-out-event", G_CALLBACK(gnc_payment_leave_amount_cb), pw); pw->amount_credit_edit = gnc_amount_edit_new (); gtk_box_pack_start (GTK_BOX (credit_box), pw->amount_credit_edit, TRUE, TRUE, 0); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (pw->amount_credit_edit), TRUE); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_credit_edit), gnc_numeric_zero()); g_signal_connect(G_OBJECT(gnc_amount_edit_gtk_entry(GNC_AMOUNT_EDIT(pw->amount_credit_edit))), "focus-out-event", G_CALLBACK(gnc_payment_leave_amount_cb), pw); box = GTK_WIDGET (gtk_builder_get_object (builder, "date_box")); pw->date_edit = gnc_date_edit_new (time(NULL), FALSE, FALSE); gtk_box_pack_start (GTK_BOX (box), pw->date_edit, TRUE, TRUE, 0); pw->docs_list_tree_view = GTK_WIDGET (gtk_builder_get_object (builder, "docs_list_tree_view")); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(pw->docs_list_tree_view)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); /* Configure date column */ renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 0); gtk_tree_view_column_pack_start (column, renderer, TRUE); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "31-12-2013"); gtk_tree_view_column_set_cell_data_func (column, renderer, (GtkTreeCellDataFunc) print_date, NULL, NULL); /* Configure document number column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 1); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "INV2013-016"); /* Configure document type column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 2); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, _("Credit Note")); /* Configure debit column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 3); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "11,999.00"); /* Configure credit column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 4); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "11,999.00"); gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (pw->docs_list_tree_view))), 0, GTK_SORT_ASCENDING); box = GTK_WIDGET (gtk_builder_get_object (builder, "acct_window")); pw->acct_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE)); gtk_container_add (GTK_CONTAINER (box), pw->acct_tree); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(pw->acct_tree), FALSE); gnc_payment_set_account_types (GNC_TREE_VIEW_ACCOUNT (pw->acct_tree)); /* Set the dialog for the 'new' owner. * Note that this also sets the post account tree. */ gnc_payment_dialog_owner_changed(pw); /* Set the dialog for the 'new' invoice */ pw->invoice = invoice; if (invoice) { Account *postacct = gncInvoiceGetPostedAcc (invoice); if (postacct) { gchar *acct_string = gnc_account_get_full_name (postacct); gnc_cbwe_set_by_string(GTK_COMBO_BOX(pw->post_combo), acct_string); gnc_payment_dialog_post_to_changed_cb (pw->post_combo, pw); g_free(acct_string); } } /* Setup signals */ gtk_builder_connect_signals_full( builder, gnc_builder_connect_full_func, pw); g_signal_connect (G_OBJECT (pw->owner_choice), "changed", G_CALLBACK (gnc_payment_dialog_owner_changed_cb), pw); g_signal_connect (G_OBJECT (pw->acct_tree), "row-activated", G_CALLBACK (gnc_payment_acct_tree_row_activated_cb), pw); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(pw->acct_tree)); g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (gnc_payment_dialog_xfer_acct_changed_cb), pw); /* Register with the component manager */ pw->component_id = gnc_register_gui_component (cm_class, gnc_payment_window_refresh_handler, gnc_payment_window_close_handler, pw); /* Watch for any new or changed accounts */ gnc_gui_component_watch_entity_type (pw->component_id, GNC_ID_ACCOUNT, QOF_EVENT_CREATE | QOF_EVENT_MODIFY | QOF_EVENT_DESTROY); /* Show it all */ gtk_widget_show_all (pw->dialog); g_object_unref(G_OBJECT(builder)); // The customer choice widget should have keyboard focus if (GNC_IS_GENERAL_SEARCH(pw->owner_choice)) { gnc_general_search_grab_focus(GNC_GENERAL_SEARCH(pw->owner_choice)); } /* Reflect if the payment could complete now */ gnc_payment_window_check_payment (pw); /* Warn the user if they have no valid post-to accounts */ { const gchar *text; const char *acct_type; text = gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(pw->post_combo))))); if (!text || g_strcmp0 (text, "") == 0) { /* The code below assumes there will only be one account type. * Let's assert this to protect from potential future changes. */ g_assert (g_list_length (pw->acct_types) == 1); acct_type = xaccAccountGetTypeStr(GPOINTER_TO_INT(pw->acct_types->data)); gnc_warning_dialog(pw->dialog, _("You have no valid \"Post To\" accounts. " "Please create an account of type \"%s\" " "before you continue to process this payment. " "Perhaps you want to create an Invoice or " "Bill first?"), acct_type); } } return pw; }
void templ_list_row_activated_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) { GncABTransDialog *td = user_data; GtkTreeModel *model; GtkTreeIter iter; GncABTransTempl *templ; const gchar *old_name, *new_name; const gchar *old_account, *new_account; const gchar *old_bankcode, *new_bankcode; const gchar *old_purpose, *new_purpose; const gchar *old_purpose_cont, *new_purpose_cont; GtkWidget *amount_widget; const gchar *old_amount_text; gnc_numeric old_amount, new_amount; g_return_if_fail(td); ENTER("td=%p", td); if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(td->template_list_store), &iter, path)) { LEAVE("Could not get iter"); return; } gtk_tree_model_get(GTK_TREE_MODEL(td->template_list_store), &iter, TEMPLATE_POINTER, &templ, -1); /* Get old values */ old_name = gtk_entry_get_text(GTK_ENTRY(td->recp_name_entry)); old_account = gtk_entry_get_text(GTK_ENTRY(td->recp_account_entry)); old_bankcode = gtk_entry_get_text(GTK_ENTRY(td->recp_bankcode_entry)); old_purpose = gtk_entry_get_text(GTK_ENTRY(td->purpose_entry)); old_purpose_cont = gtk_entry_get_text(GTK_ENTRY(td->purpose_cont_entry)); amount_widget = gnc_amount_edit_gtk_entry(GNC_AMOUNT_EDIT(td->amount_edit)); old_amount_text = gtk_entry_get_text(GTK_ENTRY(amount_widget)); old_amount = gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(td->amount_edit)); /* Get new values */ new_name = gnc_ab_trans_templ_get_recp_name(templ); new_account = gnc_ab_trans_templ_get_recp_account(templ); new_bankcode = gnc_ab_trans_templ_get_recp_bankcode(templ); new_purpose = gnc_ab_trans_templ_get_purpose(templ); new_purpose_cont = gnc_ab_trans_templ_get_purpose_cont(templ); new_amount = gnc_ab_trans_templ_get_amount(templ); if (!new_name) new_name = ""; if (!new_account) new_account = ""; if (!new_bankcode) new_bankcode = ""; if (!new_purpose) new_purpose = ""; if (!new_purpose_cont) new_purpose_cont = ""; /* Check for differences to avoid overwriting entered text */ if ((*old_name && strcmp(old_name, new_name)) || (*old_account && strcmp(old_account, new_account)) || (*old_bankcode && strcmp(old_bankcode, new_bankcode)) || (*old_purpose && strcmp(old_purpose, new_purpose)) || (*old_purpose_cont && strcmp(old_purpose_cont, new_purpose_cont)) || (*old_amount_text && !gnc_numeric_equal(old_amount, new_amount))) { if (!gnc_verify_dialog( td->parent, FALSE, _("Do you really want to overwrite your changes with the " "contents of the template \"%s\"?"), gnc_ab_trans_templ_get_name(templ))) { LEAVE("aborted"); return; } } /* Fill in */ gtk_entry_set_text(GTK_ENTRY(td->recp_name_entry), new_name); gtk_entry_set_text(GTK_ENTRY(td->recp_account_entry), new_account); gtk_entry_set_text(GTK_ENTRY(td->recp_bankcode_entry), new_bankcode); gtk_entry_set_text(GTK_ENTRY(td->purpose_entry), new_purpose); gtk_entry_set_text(GTK_ENTRY(td->purpose_cont_entry), new_purpose_cont); gnc_amount_edit_set_amount(GNC_AMOUNT_EDIT(td->amount_edit), new_amount); LEAVE(" "); }
static GncTaxTable * new_tax_table_dialog (TaxTableWindow *ttw, gboolean new_table, GncTaxTableEntry *entry, const char *name) { GncTaxTable *created_table = NULL; NewTaxTable *ntt; GtkBuilder *builder; GtkWidget *box, *widget, *combo; gboolean done; gint response, index; if (!ttw) return NULL; if (new_table && entry) return NULL; ntt = g_new0 (NewTaxTable, 1); ntt->ttw = ttw; ntt->entry = entry; ntt->new_table = new_table; if (entry) ntt->type = gncTaxTableEntryGetType (entry); else ntt->type = GNC_AMT_TYPE_PERCENT; /* Open and read the Glade File */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-tax-table.glade", "type_liststore"); gnc_builder_add_from_file (builder, "dialog-tax-table.glade", "New Tax Table Dialog"); ntt->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "New Tax Table Dialog")); ntt->name_entry = GTK_WIDGET(gtk_builder_get_object (builder, "name_entry")); if (name) gtk_entry_set_text (GTK_ENTRY (ntt->name_entry), name); /* Create the menu */ combo = GTK_WIDGET(gtk_builder_get_object (builder, "type_combobox")); index = ntt->type ? ntt->type : GNC_AMT_TYPE_VALUE; gtk_combo_box_set_active(GTK_COMBO_BOX(combo), index - 1); g_signal_connect (combo, "changed", G_CALLBACK (combo_changed), ntt); /* Attach our own widgets */ box = GTK_WIDGET(gtk_builder_get_object (builder, "amount_box")); ntt->amount_entry = widget = gnc_amount_edit_new (); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (widget), TRUE); gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (widget), 100000); gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 0); box = GTK_WIDGET(gtk_builder_get_object (builder, "acct_window")); ntt->acct_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE)); gtk_container_add (GTK_CONTAINER (box), ntt->acct_tree); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(ntt->acct_tree), FALSE); /* Make 'enter' do the right thing */ gtk_entry_set_activates_default(GTK_ENTRY (gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (ntt->amount_entry))), TRUE); /* Fix mnemonics for generated target widgets */ widget = GTK_WIDGET(gtk_builder_get_object (builder, "value_label")); gtk_label_set_mnemonic_widget (GTK_LABEL (widget), ntt->amount_entry); widget = GTK_WIDGET(gtk_builder_get_object (builder, "account_label")); gtk_label_set_mnemonic_widget (GTK_LABEL (widget), ntt->acct_tree); /* Fill in the widgets appropriately */ if (entry) { gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ntt->amount_entry), gncTaxTableEntryGetAmount (entry)); gnc_tree_view_account_set_selected_account (GNC_TREE_VIEW_ACCOUNT (ntt->acct_tree), gncTaxTableEntryGetAccount (entry)); } /* Set our parent */ gtk_window_set_transient_for (GTK_WINDOW(ntt->dialog), GTK_WINDOW(ttw->dialog)); /* Setup signals */ gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, ntt); /* Show what we should */ gtk_widget_show_all (ntt->dialog); if (new_table == FALSE) { gtk_widget_hide (GTK_WIDGET(gtk_builder_get_object (builder, "table_title"))); gtk_widget_hide (GTK_WIDGET(gtk_builder_get_object (builder, "table_name"))); gtk_widget_hide (GTK_WIDGET(gtk_builder_get_object (builder, "spacer"))); gtk_widget_hide (ntt->name_entry); /* Tables are great for layout, but a pain when you hide widgets */ widget = GTK_WIDGET(gtk_builder_get_object (builder, "ttd_table")); gtk_table_set_row_spacing (GTK_TABLE(widget), 0, 0); gtk_table_set_row_spacing (GTK_TABLE(widget), 1, 0); gtk_table_set_row_spacing (GTK_TABLE(widget), 2, 0); gtk_widget_grab_focus (gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (ntt->amount_entry))); } else gtk_widget_grab_focus (ntt->name_entry); /* Display the dialog now that we're done manipulating it */ gtk_widget_show (ntt->dialog); done = FALSE; while (!done) { response = gtk_dialog_run (GTK_DIALOG (ntt->dialog)); switch (response) { case GTK_RESPONSE_OK: if (new_tax_table_ok_cb (ntt)) { created_table = ntt->created_table; done = TRUE; } break; default: done = TRUE; break; } } g_object_unref(G_OBJECT(builder)); gtk_widget_destroy(ntt->dialog); g_free(ntt); return created_table; }
static EmployeeWindow * gnc_employee_new_window (QofBook *bookp, GncEmployee *employee) { EmployeeWindow *ew; GtkBuilder *builder; GtkWidget *hbox, *edit; gnc_commodity *currency; GNCPrintAmountInfo print_info; GList *acct_types; Account *ccard_acct; /* * Find an existing window for this employee. If found, bring it to * the front. */ if (employee) { GncGUID employee_guid; employee_guid = *gncEmployeeGetGUID (employee); ew = gnc_find_first_gui_component (DIALOG_EDIT_EMPLOYEE_CM_CLASS, find_handler, &employee_guid); if (ew) { gtk_window_present (GTK_WINDOW(ew->dialog)); return(ew); } } /* Find the default currency */ if (employee) currency = gncEmployeeGetCurrency (employee); else currency = gnc_default_currency (); /* * No existing employee window found. Build a new one. */ ew = g_new0 (EmployeeWindow, 1); ew->book = bookp; /* Find the dialog */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-employee.glade", "Employee Dialog"); ew->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Employee Dialog")); g_object_set_data (G_OBJECT (ew->dialog), "dialog_info", ew); /* Get entry points */ ew->id_entry = GTK_WIDGET(gtk_builder_get_object (builder, "id_entry")); ew->username_entry = GTK_WIDGET(gtk_builder_get_object (builder, "username_entry")); ew->name_entry = GTK_WIDGET(gtk_builder_get_object (builder, "name_entry")); ew->addr1_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr1_entry")); ew->addr2_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr2_entry")); ew->addr3_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr3_entry")); ew->addr4_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr4_entry")); ew->phone_entry = GTK_WIDGET(gtk_builder_get_object (builder, "phone_entry")); ew->fax_entry = GTK_WIDGET(gtk_builder_get_object (builder, "fax_entry")); ew->email_entry = GTK_WIDGET(gtk_builder_get_object (builder, "email_entry")); ew->language_entry = GTK_WIDGET(gtk_builder_get_object (builder, "language_entry")); ew->active_check = GTK_WIDGET(gtk_builder_get_object (builder, "active_check")); /* Currency */ edit = gnc_currency_edit_new(); gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(edit), currency); ew->currency_edit = edit; hbox = GTK_WIDGET(gtk_builder_get_object (builder, "currency_box")); gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); /* WORKDAY: Value */ edit = gnc_amount_edit_new(); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); print_info = gnc_integral_print_info (); print_info.max_decimal_places = 5; gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000); ew->workday_amount = edit; gtk_widget_show (edit); hbox = GTK_WIDGET(gtk_builder_get_object (builder, "hours_hbox")); gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); /* RATE: Monetary Value */ edit = gnc_amount_edit_new(); print_info = gnc_commodity_print_info (currency, FALSE); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), gnc_commodity_get_fraction (currency)); ew->rate_amount = edit; gtk_widget_show (edit); hbox = GTK_WIDGET(gtk_builder_get_object (builder, "rate_hbox")); gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); /* CCard Account Selection */ ew->ccard_acct_check = GTK_WIDGET(gtk_builder_get_object (builder, "ccard_check")); 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, NULL); g_list_free (acct_types); ew->ccard_acct_sel = edit; gtk_widget_show (edit); hbox = GTK_WIDGET(gtk_builder_get_object (builder, "ccard_acct_hbox")); gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); /* Setup signals */ gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, ew); /* Setup initial values */ if (employee != NULL) { GncAddress *addr; ew->dialog_type = EDIT_EMPLOYEE; ew->employee_guid = *gncEmployeeGetGUID (employee); addr = gncEmployeeGetAddr (employee); gtk_entry_set_text (GTK_ENTRY (ew->id_entry), gncEmployeeGetID (employee)); gtk_entry_set_text (GTK_ENTRY (ew->username_entry), gncEmployeeGetUsername (employee)); /* Setup Address */ gtk_entry_set_text (GTK_ENTRY (ew->name_entry), gncAddressGetName (addr)); gtk_entry_set_text (GTK_ENTRY (ew->addr1_entry), gncAddressGetAddr1 (addr)); gtk_entry_set_text (GTK_ENTRY (ew->addr2_entry), gncAddressGetAddr2 (addr)); gtk_entry_set_text (GTK_ENTRY (ew->addr3_entry), gncAddressGetAddr3 (addr)); gtk_entry_set_text (GTK_ENTRY (ew->addr4_entry), gncAddressGetAddr4 (addr)); gtk_entry_set_text (GTK_ENTRY (ew->phone_entry), gncAddressGetPhone (addr)); gtk_entry_set_text (GTK_ENTRY (ew->fax_entry), gncAddressGetFax (addr)); gtk_entry_set_text (GTK_ENTRY (ew->email_entry), gncAddressGetEmail (addr)); gtk_entry_set_text (GTK_ENTRY (ew->language_entry), gncEmployeeGetLanguage (employee)); /* Set toggle buttons */ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ew->active_check), gncEmployeeGetActive (employee)); ew->component_id = gnc_register_gui_component (DIALOG_EDIT_EMPLOYEE_CM_CLASS, gnc_employee_window_refresh_handler, gnc_employee_window_close_handler, ew); } else { employee = gncEmployeeCreate (bookp); ew->employee_guid = *gncEmployeeGetGUID (employee); ew->dialog_type = NEW_EMPLOYEE; ew->component_id = gnc_register_gui_component (DIALOG_NEW_EMPLOYEE_CM_CLASS, gnc_employee_window_refresh_handler, gnc_employee_window_close_handler, ew); } /* I know that employee exists here -- either passed in or just created */ /* Set the workday and rate values */ gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ew->workday_amount), gncEmployeeGetWorkday (employee)); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ew->rate_amount), gncEmployeeGetRate (employee)); ccard_acct = gncEmployeeGetCCard (employee); if (ccard_acct == NULL) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ew->ccard_acct_check), FALSE); gtk_widget_set_sensitive (ew->ccard_acct_sel, FALSE); } else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ew->ccard_acct_check), TRUE); gnc_account_sel_set_account (GNC_ACCOUNT_SEL (ew->ccard_acct_sel), ccard_acct, FALSE); } /* XXX: Set the ACL */ gnc_gui_component_watch_entity_type (ew->component_id, GNC_EMPLOYEE_MODULE_NAME, QOF_EVENT_MODIFY | QOF_EVENT_DESTROY); gtk_widget_show_all (ew->dialog); if (ccard_acct == NULL) gtk_widget_hide (ew->ccard_acct_sel); g_object_unref(G_OBJECT(builder)); return ew; }