26 #include <glib/gi18n.h> 27 #include "business-options-gnome.h" 31 #include <business-gnome-utils.h> 33 #include <gnc-general-search.h> 34 #include "dialog-utils.h" 36 #include "gnc-report-combo.h" 42 #include "gnc-option-gtk-ui.hpp" 45 #define FUNC_NAME G_STRFUNC 48 static inline GncOwnerType
51 if (ui_type == GncOptionUIType::CUSTOMER)
52 return GNC_OWNER_CUSTOMER;
53 if (ui_type == GncOptionUIType::VENDOR)
54 return GNC_OWNER_VENDOR;
55 if (ui_type == GncOptionUIType::EMPLOYEE)
56 return GNC_OWNER_EMPLOYEE;
57 if (ui_type == GncOptionUIType::JOB)
60 std::ostringstream oss;
61 oss <<
"UI type " <<
static_cast<unsigned int>(ui_type) <<
" could not be converted to owner type\n";
62 throw std::invalid_argument(oss.str());
71 void set_ui_item_from_option(
GncOption& option) noexcept
override 73 auto owner = option.get_value<
const GncOwner*>();
74 gnc_owner_set_owner(get_widget(), owner);
76 void set_option_from_ui_item(
GncOption& option) noexcept
override 79 gnc_owner_get_owner(get_widget(), &owner);
80 if (owner.type == ui_type_to_owner_type(option.get_ui_type()))
81 option.set_value<
const GncOwner*>(&owner);
86 create_option_widget<GncOptionUIType::OWNER>(
GncOption& option,
87 GtkGrid *page_box,
int row)
90 auto ui_type{option.get_ui_type()};
91 owner.type = ui_type_to_owner_type(ui_type);
92 auto enclosing{gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5)};
93 gtk_box_set_homogeneous (GTK_BOX (enclosing), FALSE);
94 auto widget = gnc_owner_select_create(
nullptr, enclosing,
95 gnc_get_current_book(),
98 option.set_ui_item(std::make_unique<GncGtkOwnerUIItem>(widget, ui_type));
99 option.set_ui_item_from_option();
100 g_signal_connect (G_OBJECT (widget),
"changed",
101 G_CALLBACK (gnc_option_changed_widget_cb), &option);
102 set_name_label(option, page_box, row,
false);
103 set_tool_tip(option, enclosing);
104 grid_attach_widget(page_box, enclosing, row);
112 void set_ui_item_from_option(
GncOption& option) noexcept
override 114 auto instance{option.get_value<
const QofInstance*>()};
116 gnc_general_search_set_selected(GNC_GENERAL_SEARCH(get_widget()),
117 GNC_INVOICE(instance));
119 void set_option_from_ui_item(
GncOption& option) noexcept
override 121 option.set_value(qof_instance_cast(gnc_general_search_get_selected(GNC_GENERAL_SEARCH(get_widget()))));
126 create_option_widget<GncOptionUIType::INVOICE>(
GncOption& option,
127 GtkGrid *page_box,
int row)
129 auto enclosing{gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5)};
130 gtk_box_set_homogeneous (GTK_BOX (enclosing), FALSE);
131 auto widget{gnc_invoice_select_create(enclosing, gnc_get_current_book(),
132 nullptr,
nullptr,
nullptr)};
134 option.set_ui_item(std::make_unique<GncGtkInvoiceUIItem>(widget));
135 option.set_ui_item_from_option();
136 g_signal_connect(G_OBJECT (widget),
"changed",
137 G_CALLBACK (gnc_option_changed_widget_cb), &option);
139 set_name_label(option, page_box, row,
false);
140 set_tool_tip(option, enclosing);
141 grid_attach_widget(page_box, enclosing, row);
149 void set_ui_item_from_option(
GncOption& option) noexcept
override 151 auto taxtable{option.get_value<
const QofInstance*>()};
153 gnc_simple_combo_set_value(GTK_COMBO_BOX(get_widget()),
154 GNC_TAXTABLE(taxtable));
156 gnc_simple_combo_set_value(GTK_COMBO_BOX(get_widget()),
159 void set_option_from_ui_item(
GncOption& option) noexcept
override 161 auto taxtable{gnc_simple_combo_get_value(GTK_COMBO_BOX(get_widget()))};
162 option.set_value<
const QofInstance*>(qof_instance_cast(taxtable));
167 create_option_widget<GncOptionUIType::TAX_TABLE>(
GncOption& option,
168 GtkGrid *page_box,
int row)
170 constexpr
const char* glade_file{
"business-options-gnome.glade"};
171 constexpr
const char* glade_store{
"taxtable_store"};
172 constexpr
const char* glade_menu{
"taxtable_menu"};
173 auto builder{gtk_builder_new()};
174 gnc_builder_add_from_file(builder, glade_file, glade_store);
175 gnc_builder_add_from_file(builder, glade_file, glade_menu);
176 auto widget{GTK_WIDGET(gtk_builder_get_object(builder, glade_menu))};
177 gnc_taxtables_combo(GTK_COMBO_BOX(widget), gnc_get_current_book(), TRUE,
179 option.set_ui_item(std::make_unique<GncGtkTaxTableUIItem>(widget));
180 option.set_ui_item_from_option();
181 g_object_unref(builder);
182 g_signal_connect (G_OBJECT (widget),
"changed",
183 G_CALLBACK (gnc_option_changed_widget_cb), &option);
185 wrap_widget(option, widget, page_box, row);
193 void set_ui_item_from_option(
GncOption& option) noexcept
override 195 std::string guid_string;
196 auto str{option.get_value<std::string>()};
200 static const std::string default_guid_string(gnc_get_builtin_default_invoice_print_report ());
201 guid_string = default_guid_string +
"/ ";
206 gnc_report_combo_set_active_guid_name (GNC_REPORT_COMBO(get_widget()),
207 guid_string.c_str());
209 void set_option_from_ui_item(
GncOption& option) noexcept
override 211 auto report_guid_name = gnc_report_combo_get_active_guid_name (GNC_REPORT_COMBO(get_widget()));
212 option.set_value(std::string{report_guid_name});
213 g_free (report_guid_name);
218 create_option_widget<GncOptionUIType::INV_REPORT>(
GncOption& option,
222 constexpr
const char* inv_report{
"gnc:custom-report-invoice-template-guids"};
223 auto widget = gnc_default_invoice_report_combo (inv_report);
224 option.set_ui_item(std::make_unique<GncGtkInvReportUIItem>(widget));
225 option.set_ui_item_from_option();
227 g_signal_connect (G_OBJECT (widget),
"changed",
228 G_CALLBACK (gnc_option_changed_widget_cb), &option);
230 wrap_widget (option, widget, page_box, row);
237 create_option_widget<GncOptionUIType::OWNER>);
239 create_option_widget<GncOptionUIType::OWNER>);
241 create_option_widget<GncOptionUIType::OWNER>);
243 create_option_widget<GncOptionUIType::OWNER>);
245 create_option_widget<GncOptionUIType::OWNER>);
247 create_option_widget<GncOptionUIType::INVOICE>);
249 create_option_widget<GncOptionUIType::TAX_TABLE>);
251 create_option_widget<GncOptionUIType::INV_REPORT>);
static void set_func(GncOptionUIType type, WidgetCreateFunc func)
Register a WidgetCreateFunc.
Business Interface: Object OWNERs.
utility functions for the GnuCash UI
Represents the public interface for an option.
C++ Public interface for individual options.
class GncOptionGtkUIItem Gtk-specific Interface class for Option Widget
GncOptionUIType
Used by GncOptionClassifier to indicate to dialog-options what control should be displayed for the op...
void gnc_business_options_gnome_initialize(void)
Set up the business and counters pages in the File Preferences dialog.